View Source Mongo.GridFs.Bucket (mongodb-driver v1.4.1)

This is the MongoDB Bucket struct, which specifies the underlying collections to support GridFS. There are always two kind of collections used for storing files by GridFS. The fs.files collection contains the meta information about the file and the fs.chunks collection contains the data of the file chunked into blocks of bytes. The names of the collection and the size of the block is defined by the following options:

The bucket has some configuration options:

  • :chunk_size - The chunk size in bytes. Defaults to 255*1024
  • :name - The bucket name. Defaults to fs

The bucket checks whether the indexes already exist before attempting to create them. The names of the created indexes are "filename_1_uploadDate_1" and "files_id_1_n_1"

Summary

Functions

In case of using transaction you need to add the session to the bucket. This functions adds the session pid to the bucket.

Returns the collection name for the chunks collection, default is fs.chunks.

Given a id, delete this stored file’s files collection document and associated chunks from a GridFS bucket.

Drops the files and chunks collections associated with this bucket.

Returns the collection name for the files collection, default is fs.files.

Returns a cursor from the fs.files collection.

Finds one file document by file_id specified either as a string or BSON.ObjectId.

Creates a new Bucket with a existing connection using the default values. It just contains the name of the collections (fs) and the chunk size (255KB).

Renames the stored file with the specified file_id.

Types

@type t() :: %Mongo.GridFs.Bucket{
  chunk_size: non_neg_integer(),
  name: String.t(),
  opts: term(),
  topology_pid: GenServer.server()
}

Functions

Link to this function

add_session(bucket, session_opts)

View Source

In case of using transaction you need to add the session to the bucket. This functions adds the session pid to the bucket.

Link to this function

check_and_chunks_files_index(bucket)

View Source
Link to this function

check_and_create_files_index(bucket)

View Source
Link to this function

chunks_collection_name(bucket)

View Source
@spec chunks_collection_name(t()) :: String.t()

Returns the collection name for the chunks collection, default is fs.chunks.

@spec delete(t(), String.t()) :: {:ok, Mongo.DeleteResult.t()}
@spec delete(t(), BSON.ObjectId.t()) :: {:ok, Mongo.DeleteResult.t()}

Given a id, delete this stored file’s files collection document and associated chunks from a GridFS bucket.

@spec drop(t()) :: :ok | {:error, Mongo.Error.t()}

Drops the files and chunks collections associated with this bucket.

Link to this function

files_collection_name(bucket)

View Source
@spec files_collection_name(t()) :: String.t()

Returns the collection name for the files collection, default is fs.files.

Link to this function

find(bucket, filter, opts \\ [])

View Source
@spec find(t(), BSON.document(), Keyword.t()) :: Mongo.cursor()

Returns a cursor from the fs.files collection.

Link to this function

find_one(bucket, file_id)

View Source
@spec find_one(t(), String.t()) :: BSON.document() | nil
@spec find_one(t(), BSON.ObjectId.t()) :: BSON.document() | nil

Finds one file document by file_id specified either as a string or BSON.ObjectId.

Link to this function

index_member?(topology_pid, coll, index, opts)

View Source
Link to this function

new(topology_pid, options \\ [])

View Source
@spec new(GenServer.server(), Keyword.t()) :: t()

Creates a new Bucket with a existing connection using the default values. It just contains the name of the collections (fs) and the chunk size (255KB).

The bucket checks the index for both collections as well. In case of multiple upload or downloads just create only one bucket and reuse it.

Link to this function

rename(bucket, file_id, new_filename)

View Source
@spec rename(t(), BSON.ObjectId.t(), String.t()) :: Mongo.result(BSON.document())

Renames the stored file with the specified file_id.