Noomman

Nodejs Object-Oriented MongoDB Manager


Class noomman

Methods

connect(uri, databaseName)
Description

Connects to the mongo database with the given uri and databaseName.

Parameters
Name Type Description
uri String A uri string of the database to connect to.
databaseName String The name of the database to connect to.
Returns

Promise<mongodb.Db> - The database object returned by mongodb.MongoClient.connect().

Throws
Error Type Cause
NoommanDatabaseError If an attempt is made to connect to a database more than once without calling close().
MongoError If underlying call to mongodb.MongoCLient.connect() throws an error.
close()
Description

Closes the connection to a mongo db that was established by calling connect().

Returns

Promise<undefined> - A promise which will resolve undefined if connection is closed successfully.

connected()
Description

Use to determine if a connection to a database is active.

Returns

Boolean - True if connection to database is active, false otherwise.

ObjectId(hexString)
Description

Creates a new ObjectId either from the given hexString or by calling new mongodb.ObjectId().

Parameters
Name Type Description
hexString String A 24 byte hex string.
Returns

mongodb.ObjectId - A native mongo ObjectId object.

Throws
Error Type Cause
MongoError If given hexString is invalid.