It wraps all Methods of mongodb collection api.
The official MongoDB driver is multi-functional. However, "close db" or "requires toArray () when finding" is troublesome. This wrapper simplifies them.
$ npm install monwrap
const MongoWrapper = require('monwrap')
const settings = {
user: 'username',
pass: 'password',
dbName: 'database_name'
}
const mongo = new MongoWrapper(settings, 'collectionName')
await mongo.insertMany([{ _id: 1 }, { _id: 3 }], {w: 1})
const items = await mongo.find({})
node-mongodb-native Class: Collection
const MongoWrapper = require('monwrap')
const data = [{ _id: 1, a: 11 }]
MongoWrapper.toBulkArray(data)
/* ->
[
{
'updateOne': {
'filter': { '_id': 1 },
'update': { '_id': 1, 'a': 11 },
'upsert': true
}
}
]
*/
const data = [{ x: 1, a: 11 }]
MongoWrapper.toBulkArray(data, 'x')
/* ->
[
{
'updateOne': {
'filter': { '_id': 1 },
'update': { '_id': 1, 'a': 11, x: 1 },
'upsert': true
}
}
]
*/
mongodb The official MongoDB driver for Node.js. Provides a high-level API on top of mongodb-core that is meant for end users.
MIT © Mick Whats