This is a simple wrapper for the new MongoDB GridFSBucket-API (http://mongodb.github.io/node-mongodb-native/3.0/tutorials/gridfs/streaming/). The old GridStore-API is now deprecated (http://mongodb.github.io/node-mongodb-native/3.0/tutorials/gridfs/gridstore/).
How to install
That is simple
npm install gridfs-promise
const mongoOptions: MongoClientOptions =autoReconnect: trueuseNewUrlParser: true;let gridFS = "test" "mongodb://localhost:27017/test" mongoOptions __dirname "attachments";gridFS;
By this method you can simple upload files by a base64 string
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.
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.
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:
Mongoose & Other MongoClient Connections
You can use you already existing MongoDB connection with the library.
;;test.CONNECTION = mongoDBConnection;
Use GridFS Promise together with NestJS
It is really simple to use GridFS Promise together with NestJs.
Install the dependency via
npm install gridfs-promise --save.
In the Module where you want to use GridFS create a simple Provider to Load the Lib