Class: MongoClient

MongoClient

Creates a new MongoClient instance

Returns:
MongoClient instance.

Methods

staticMongoClient.connect(url, options, callback){Promise}

Connect to MongoDB using a url as documented at

docs.mongodb.org/manual/reference/connection-string/

Note that for replicasets the replicaSet query parameter is required in the 2.0 driver

Name Type Default Description
url string

The connection URI string

options object null optional

Optional settings.

Name Type Default Description
uri_decode_auth boolean false optional

Uri decode the user name and password for authentication

db object null optional

A hash of options to set on the db object, see Db constructor

server object null optional

A hash of options to set on the server objects, see Server constructor**

replSet object null optional

A hash of options to set on the replSet object, see ReplSet constructor**

mongos object null optional

A hash of options to set on the mongos object, see Mongos constructor**

promiseLibrary object null optional

A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible

callback MongoClient~connectCallback optional

The command result callback

Returns:
Promise if no callback passed

connect(url, options, callback){Promise}

Connect to MongoDB using a url as documented at

docs.mongodb.org/manual/reference/connection-string/

Note that for replicasets the replicaSet query parameter is required in the 2.0 driver

Name Type Default Description
url string

The connection URI string

options object null optional

Optional settings.

Name Type Default Description
uri_decode_auth boolean false optional

Uri decode the user name and password for authentication

db object null optional

A hash of options to set on the db object, see Db constructor

server object null optional

A hash of options to set on the server objects, see Server constructor**

replSet object null optional

A hash of options to set on the replSet object, see ReplSet constructor**

mongos object null optional

A hash of options to set on the mongos object, see Mongos constructor**

promiseLibrary object null optional

A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible

callback MongoClient~connectCallback optional

The command result callback

Returns:
Promise if no callback passed

Type Definitions

connectCallback(error, db)

The callback format for results

Name Type Description
error MongoError

An error instance representing the error during the execution.

db Db

The connected database.

comments powered by Disqus