0.0.4 • Published 7 years ago

cdi-mongo-connect v0.0.4

Weekly downloads
14
License
MIT
Repository
github
Last release
7 years ago

cdi-mongo-connect

Made for our boilerplate.

Install

npm install cdi-mongo-connect --save

Feature(s?)

  • Mongo connect only once!

Usage

Adding database config

On your index.js / server.js / app.js, register your database using a key.

const mongo = require('cdi-mongo-connect');

mongo.connect({
    host: 'localhost',
    port: 27017,
    database: 'testdb'
});

// with auth
mongo.connect({
    host: 'localhost',
    user: 'john',
    password: 'password',
    port: 27017,
    database: 'testdb'
});

// with URL string
mongo.connect('mongodb://localhost:27017/myproject');

Doing a single query

After registering a db key and config, you can now start querying.

const mongo = require('cdi-mongo-connect');
/* ... */
const user  = mongo.db.collection('user');

user
.findOne(
    {'email': data.email},
    callback
)

License

MIT

0.0.4

7 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago

0.0.0

8 years ago