mongo-gridfs
This is a simple wrapper for the new MongoDB GridFSBucket API.
The old GridStore-API is now deprecated.
How to install
That is simple
npm install mongo-gridfs
OR
yarn add mongo-gridfs
Usage
With MongoClient
const mongoDBConnection = await MongoClient;let gridFS = mongoDBConnection "attachments";gridFS;
With Mongoose
const mongooseConnection = await Mongoose;let gridFS = mongooseConnectiondb "attachments";gridFS;
Methods
findById
By this method you will simple get the meta-object from the MongoDB as a Promise-Object. If nothing found at the Database, then it will reject and the catch-block will be executed.
gridFS;
downloadFile
You will get the file simple written to the filesystem directly from the Database. If nothing found at the Database, then it will reject and the catch-block will be executed.
gridFS;
readFileStream
You will get a GridFSBucketReadStream as Promise. If nothing found at the Database, then it will reject and the catch-block will be executed.
This method is very useful, to stream the content directly to the user.
For example with express:
return gridFS;