GridFS is a specification for storing large files in MongoDB. All of the mongodb.com supported drivers implement the GridFS spec.
GridFS is a specification for storing large files in MongoDB. MongoDB supports storing binary data directly within BSON documents, however the size is limited by the database's maximum document size (16MB as of the 1.8 production version of MongoDB; 4MB in older versions).
GridFS works by splitting large files into small "chunks", usually 256k in size.
GridFS uses two collections to store data:
chunks
contains the binary segments of filesfiles
contains metadata including the filename, content type, md5 checksum, and any optional information added by the developer
Each file saved in GridFS will have one document in the files
collection and one or more documents in the chunks
collection.
The GridFS collections also use a prefix (aka namespace). The default prefix is fs
, so the default collection names are fs.chunks
and fs.files
.
GridFS collections are stored in normal MongoDB databases, and can be scaled with standard features such as replication and sharding.
Working with GridFS
All of the mongodb.org supported drivers implement the GridFS spec.
The command-line utility mongofiles
can also be used to save, retrieve, list, search, and remove files in GridFS.