gridfs-store
This is a simple wrapper for the new MongoDB GridFSBucket API.
How to install
That is simple
npm install --save gridfs-store
OR
yarn add gridfs-store
Parameters
hosts
Specify the list of hosts to connect to. Format
host: 'host1' port: 27017 host: 'host2' port: 27017
database
The name of the database to be used
replicaSet
The name of the replica to be used
Usage
;; async { const store = database: 'testDatabase' ; await store; const filename = 'testDir/test.txt'; const uploadFilePath = path; let item = await store; await store; await store; process;};
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.
store;
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.
store;
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 store;