- 数据模型 >
- Data Model Reference >
- GridFS Reference
GridFS Reference¶
GridFS stores files in two collections:
- chunks stores the binary chunks. For details, see The chunks Collection.
- files stores the file’s metadata. For details, see The files Collection.
GridFS places the collections in a common bucket by prefixing each with the bucket name. By default, GridFS uses two collections with names prefixed by fs bucket:
- fs.files
- fs.chunks
You can choose a different bucket name than fs, and create multiple buckets in a single database.
参见
GridFS for more information about GridFS.
The chunks Collection¶
Each document in the chunks collection represents a distinct chunk of a file as represented in the GridFS store. The following is a prototype document from the chunks collection.:
{
"_id" : <ObjectId>,
"files_id" : <ObjectId>,
"n" : <num>,
"data" : <binary>
}
A document from the chunks collection contains the following fields:
- chunks.files_id¶
The _id of the “parent” document, as specified in the files collection.
- chunks.n¶
The sequence number of the chunk. GridFS numbers all chunks, starting with 0.
The chunks collection uses a compound index on files_id and n, as described in GridFS Index.
The files Collection¶
Each document in the files collection represents a file in the GridFS store. Consider the following prototype of a document in the files collection:
{
"_id" : <ObjectId>,
"length" : <num>,
"chunkSize" : <num>,
"uploadDate" : <timestamp>,
"md5" : <hash>,
"filename" : <string>,
"contentType" : <string>,
"aliases" : <string array>,
"metadata" : <dataObject>,
}
Documents in the files collection contain some or all of the following fields. Applications may create additional arbitrary fields:
- files._id¶
The unique ID for this document. The _id is of the data type you chose for the original document. The default type for MongoDB documents is BSON ObjectId.
- files.length¶
The size of the document in bytes.
- files.chunkSize¶
The size of each chunk. GridFS divides the document into chunks of the size specified here. The default size is 255 kilobytes.
在 2.4.10 版更改: The default chunk size changed from 256k to 255k.
- files.uploadDate¶
The date the document was first stored by GridFS. This value has the Date type.
- files.filename¶
Optional. A human-readable name for the document.
- files.contentType¶
Optional. A valid MIME type for the document.
- files.aliases¶
Optional. An array of alias strings.
- files.metadata¶
Optional. Any additional information you want to store.