MongoDB.createManager()

Build and initialize a connection manager instance (in Mongo, this is `db`).

The `manager` instance returned by this method contains any configuration that is necessary for communicating with the database and establishing connections (e.g. host, user, password) as well as any other relevant metadata. The manager will often also contain a reference to some kind of native container (e.g. a connection pool). Note that a manager instance does not necessarily need to correspond with a pool though--it might simply be a container for storing config, or it might refer to multiple pools (e.g. a ClusterPool from felixge's `mysql` package).

Usage

Hover over inputs/exits for more info.

var MongoDB = require('machinepack-mongo');


// Build and initialize a connection manager instance (in Mongo, this is `db`).

MongoDB.createManager({

connectionString: '===',

onUnexpectedFailure: '===',

meta: '===',

}).exec({

// An unexpected error occurred.

error: function (err) {

 

},

// The provided connection string is malformed.

malformed: function (result) {

 

},

// Could not connect to Mongo using the specified connection URL.

failed: function (result) {

 

},

// OK.

success: function (result) {

 

},

});

Inputs

connectionString required

The Mongo connection URL containing the configuration/credentials necessary for connecting to the database.

'==='
onUnexpectedFailure

A notifier function for otherwise-unhandled error events. (WARNING: Currently, this is ignored by mp-mongo!)

'==='
meta

A dictionary of additional options to pass in when instantiating the Mongo client instance. (e.g. `{ssl: true}`)

'==='

Exits

error

An unexpected error occurred.

malformed

The provided connection string is malformed.

{ error: '===', meta: '===' }
failed

Could not connect to Mongo using the specified connection URL.

{ error: '===', meta: '===' }
success

OK.

'==='