1.0.1 • Published 8 years ago
mongodb-connector v1.0.1
mongodb-connector
Simple wrapper around the MongoClient.connect method Can include an optional collections array on the options object so that your collections can be accessed via the returned mongodb instance object.
var options = {
collections: ['collectiona','collectionb','collectionc']
};
install $npm install --save --production mongodb-connector
usage
const MongoConnector = require('mongodb-connector');
let url = 'mongodb://localhost:27017/test_db';
let options = {
collections: ['collectiona', 'collectionb', 'collectionc']
}
new MongoConnector().connect(url, options).then(function(db){
db.collectiona.insertOne({name: 'test'}).then(function(){
//access to the default returned db instance
db.db.collection('collectiona').insertOne({name: 'test2'}).then(function(){
db.close();
});
});
}, function(error){
console.log(error);
});