@terrajs/mono-mongodb

2.2.0 • Public • Published

mono-mongodb

MongoDB module for Mono.

npm version Travis Coverage license

Installation

npm install --save @terrajs/mono-mongodb

Then, in your configuration file of your Mono application (example: conf/application.js):

module.exports = {
  mono: {
    modules: ['@terrajs/mono-mongodb']
  }
}

Configuration

Mono-MongoDB will use the mongodb property of your configuration (example: conf/development.js):

module.exports = {
  mono: {
    mongodb: {
      url: 'mongodb://localhost:27017/my-db',
      dropDatabase: true //Drop database at launch
      // options property is optional
      options: {
        // See http://mongodb.github.io/node-mongodb-native/2.2/api/MongoClient.html#connect
      }
    }
  }
}

You can set mongodb.dropDatabase: true to drop the database when connected (useful for tests).

Usage

In your modules files, you can access db instance and oid(id) helper like this:

const { db, oid } = require('@terrajs/mono-mongodb')

const users = db.collection('users')

users.findOne({ _id: oid('554ab...' }))

Package Sidebar

Install

npm i @terrajs/mono-mongodb

Weekly Downloads

2

Version

2.2.0

License

MIT

Last publish

Collaborators

  • gaetansenn
  • alexchopin
  • benjamincanac
  • atinux