monwrap

1.1.0 • Public • Published

monwrap

It wraps all Methods of mongodb collection api.

Build Status

The official MongoDB driver is multi-functional. However, "close db" or "requires toArray () when finding" is troublesome. This wrapper simplifies them.

Install

$ npm install monwrap

Usage

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({})

API

node-mongodb-native Class: Collection

static API

toBulkArray(array, idName = '_id')

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
    }
  }
]
*/

Related

mongodb The official MongoDB driver for Node.js. Provides a high-level API on top of mongodb-core that is meant for end users.

License

MIT © Mick Whats

Dependencies (1)

Dev Dependencies (10)

Package Sidebar

Install

npm i monwrap

Weekly Downloads

0

Version

1.1.0

License

MIT

Unpacked Size

8.71 kB

Total Files

5

Last publish

Collaborators

  • whats