doix-mongodb
v1.0.7
Published
MongoDB support for doix
Downloads
12
Readme
doix-mongodb is a plug in for the doix framework implementing an interface to MongoDB.
Usage
Adding to the project
In your package.js:
"peerDependencies": {
...
"doix-mongodb": "^1.0.6"
...
},Then,
npm iDeclaring a Connection Pool at the Application Level
const MongoDB = require ('doix-mongodb')
module.exports = class extends Application {
constructor (conf, logger) {
super ({
logger,
pools: {
mongo: new MongoDB ({...conf.mongodb, logger}),
//...
},
//...
},
//...
}
}Writing Data from a Workflow Module
await this.mongo.insertMany (collectionName, listOfDocuments)
await this.mongo.updateOne (collectionName, filter, singleDocument, options)
await this.mongo.bulkWrite (collectionName, listOfDocuments, options)
const documents = await (await mongo.find (collectionName, filter)).toArray () // sic: `await` bisMethods
bulkWrite
For MongoDB 8+, a shortcut for the underlying driver's bulkWrite. Otherwise, an emulation using Promise.all ().
insertMany
Shortcut for the underlying driver's insertMany.
find
Shortcut for the underlying driver's find.
Note: here, the .find () method is asynchronous and so is its result's .toArray (). So you need double await when using .toArray () (see the example above).
updateOne
Shortcut for the underlying driver's updateOne.
