MongoDB Documentation, Release 3.0.4 GridFS Collections GridFS Index Additional Resources 4.3 Data Model Examples and Patterns GridFS stores files in two collections: 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: You can choose a different bucket name than fs , and create multiple buckets in a single database. Each document in the chunks collection represents a distinct chunk of a file as represented in the GridFS store. Each chunk is identified by its unique ObjectId stored in its _id field. For descriptions of all fields in the chunks and files collections, see GridFS Reference (page 174). GridFS uses a unique , compound index on the chunks collection for the files_id and n fields. The files_id field contains the _id of the chunk’s “parent” document. The n field contains the sequence number of the chunk. GridFS numbers all chunks, starting with 0. For descriptions of the documents and fields in the chunks collection, see GridFS Reference (page 174). The GridFS index allows efficient retrieval of chunks using the files_id and n values, as shown in the following example: cursor = db.fs.chunks.find({files_id: myFileID}).sort({n:1}); See the relevant driver documentation for the specific behavior of your GridFS application. If your driver does not create this index, issue the following operation using the mongo shell: db.fs.chunks.createIndex( { files_id: 1, n: 1 }, { unique: true } ); The following documents provide overviews of various data modeling patterns and common schema design consider- ations: Model Relationships Between Documents (page 152) Examples for modeling relationships between documents. Model One-to-One Relationships with Embedded Documents (page 152) Presents a data model that uses em- bedded documents (page 146) to describe one-to-one relationships between connected data. • Building MongoDB Applications with Binary Files Using GridFS: Part 2 11 • Building MongoDB Applications with Binary Files Using GridFS: Part 1 10 • fs.chunks • fs.files • chunks stores the binary chunks. For details, see The chunks Collection (page 174). • files stores the file’s metadata. For details, see The files Collection (page 175). $^{10}$http://www.mongodb.com/blog/post/building-mongodb-applications-binary-files-using-gridfs-part-1?jmp=docs $^{11}$http://www.mongodb.com/blog/post/building-mongodb-applications-binary-files-using-gridfs-part-2?jmp=docs 151 4.3. Data Model Examples and Patterns