Mongotoolbox
MongoDB toolbox for index management and simple connection to authorized database
Using
This utility requires:
- Node.js
>= 6.0.0
- mongodb driver
^2.2.4
Install package with npm:
npm i -S mongotools
Ensure indexes at collection
const mongotools = require('mongotools');
mongotools.ensureIndex(db.collection('myCollection'))
.index({ someUniqueIndex: 1 }, { sparse: true, unique: true })
.writeIndexes();
Connect to database
const mongotools = require('mongotools');
mongotools.connectAndAuth('mongodb://localhost:27017')
.then((db) => {
});
Connect to database and authenticate
const mongotools = require('mongotools');
const url = 'mongodb://localhost:27017';
const options = { user: 'username', password: 'foo' };
mongotools
.connectAndAuth(url, options)
.then((db) => {
});
API
connectAndAuth method
- connectAndAuth(url: string, options: object)
url
: mongodb connection stringoptions
options for mongodb connect method
options.user
: username for authenticationoptions.password
: password for authentication
EnsureIndex class