mongodb-connectordeprecated

Simple wrapper for mongodb.MongoClient

Usage no npm install needed!

<script type="module">
  import mongodbConnector from 'https://cdn.skypack.dev/mongodb-connector';
</script>

README

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']
};

see [mongodb options](https://docs.mongodb.org/v3.0/reference/connection-string/#connections-connection-options) for other valid properties for he options object.

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);
});