GridStore

GridFS is a scalable MongoDB filesystem for storing and retrieving large files. The default limit for a MongoDB record is
16MB, so to store data that is larger than this limit, GridFS can be used. GridFS shards the data into smaller chunks automatically.
See MongoDB documentation for details.

GridStore is a single file inside GridFS that can be managed by the script.

Open GridStore

Opening a GridStore (a single file in GridFS) is a bit similar to opening a database. At first you need to create a GridStore object and then open it.

var gs = new mongodb.GridStore(db, filename, mode[, options])

Where

db is the database object

filename is the name of the file in GridFS that needs to be accessed/created

mode indicated the operaion, can be one of:

"r" (Read): Looks for the file information in fs.files collection, or creates a new id for this object.

"w" (Write): Erases all chunks if the file already exist.

"w+" (Append): Finds the last chunk, and keeps writing after it.

options can be used to specify some metadata for the file, for example content_type, metadata and chunk_size