Implementing a GridStore Object from Node.js
The GridStore
object acts as a representation of a binary file stored in the MongoDB GridFS. It provides the basic file interface to read and write files stored in GridFS. For example, you can stream reads and writes from GridFS, read chunks of a file without needing to read the entire file, etc. These are all things that you could do within Node.js, but without the added benefits that come with MongoDB, such as replication and high availability.
You can instantiate the GridStore
object by calling the GridStore()
constructor from an instance of the Db
object. For example, the following code connects to MongoDB and creates a GridStore
object attached to the fs
collection:
Get Node.js, MongoDB, and AngularJS Web Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.