Returns a promise that resolves when this connection successfully connects to MongoDB
Closes the connection
Closes and destroys the connection. Connection once destroyed cannot be reopened
Retrieves a collection, creating it if not cached.
Helper for createCollection()
. Will explicitly create the given collection
with specified options. Used to create capped collections
and views from mongoose.
Removes the model named name
from this connection, if it exists. You can
use this function to clean up any models you created in your tests to
prevent OverwriteModelErrors.
Helper for dropCollection()
. Will delete the given collection, including
all documents and indexes.
Helper for dropDatabase()
. Deletes the given database, including all
collections, documents, and indexes.
Gets the value of the option key
.
Returns the MongoDB driver MongoClient
instance
that this connection uses to talk to MongoDB.
Defines or retrieves a model.
Returns an array of model names created on this connection.
Opens the connection with a URI using MongoClient.connect()
.
Declares a plugin executed on all schemas you pass to conn.model()
Sets the value of the option key
.
Set the MongoDB driver MongoClient
instance
that this connection uses to talk to MongoDB. This is useful if you already have a MongoClient instance, and want to
reuse it.
Requires MongoDB >= 3.6.0. Starts a MongoDB session for benefits like causal consistency, retryable writes, and transactions.
Makes the indexes in MongoDB match the indexes defined in every model's
schema. This function will drop any indexes that are not defined in
the model's schema except the _id
index, and build any indexes that
are in your schema but not in MongoDB.
Requires MongoDB >= 3.6.0. Executes the wrapped async function in a transaction. Mongoose will commit the transaction if the async function executes successfully and attempt to retry if there was a retryable error.
Switches to a different database using the same connection pool.
Watches the entire underlying database for changes. Similar to Model.watch()
.
This symbol shall be used to install a listener for only monitoring 'error'
events. Listeners installed using this symbol are called before the regular
'error'
listeners are called.
Installing a listener using this symbol does not change the behavior once an
'error'
event is emitted, therefore the process will still crash if no
regular 'error'
listener is installed.
Sets or gets the default captureRejection value for all emitters.
A hash of the collections associated with this connection
A hash of the global options that are associated with this connection
The mongodb.Db instance, set when the connection is opened
The host name portion of the URI. If multiple hosts, such as a replica set, this will contain the first host name in the URI
A number identifier for this connection. Used for debugging when you have multiple connections.
A POJO containing
a map from model names to models. Contains all models that have been
added to this connection using Connection#model()
.
The name of the database this connection points to.
The password specified in the URI
The port portion of the URI. If multiple hosts, such as a replica set, this will contain the port from the first host name in the URI.
The plugins that will be applied to all models created on this connection.
Connection ready state
The username specified in the URI
Generated using TypeDoc
since v4.0.0