new MongoClient(){MongoClient}
Creates a new MongoClient instance
Returns:
MongoClient instance.Methods
-
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 urlstring The connection URI string
optionsobject null optional Optional settings.
Name Type Default Description uri_decode_authboolean false optional Uri decode the user name and password for authentication
dbobject null optional A hash of options to set on the db object, see Db constructor
serverobject null optional A hash of options to set on the server objects, see Server constructor**
replSetobject null optional A hash of options to set on the replSet object, see ReplSet constructor**
mongosobject null optional A hash of options to set on the mongos object, see Mongos constructor**
promiseLibraryobject null optional A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible
callbackMongoClient~connectCallback optional The command result callback
Returns:
Promise if no callback passed
-
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 urlstring The connection URI string
optionsobject null optional Optional settings.
Name Type Default Description uri_decode_authboolean false optional Uri decode the user name and password for authentication
dbobject null optional A hash of options to set on the db object, see Db constructor
serverobject null optional A hash of options to set on the server objects, see Server constructor**
replSetobject null optional A hash of options to set on the replSet object, see ReplSet constructor**
mongosobject null optional A hash of options to set on the mongos object, see Mongos constructor**
promiseLibraryobject null optional A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible
callbackMongoClient~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 errorMongoError An error instance representing the error during the execution.
dbDb The connected database.