Connection Methods

Note

For details on specific methods, including syntax and examples,click on the specific method to go to its reference page.

NameDescription
connect()Connects to a MongoDB instance and to a specified database on that instance.
Mongo()Creates a new connection object.
Mongo.getDB()Returns a database object.
Mongo.getReadPrefMode()Returns the current read preference mode for the MongoDB connection.
Mongo.getReadPrefTagSet()Returns the read preference tag set for the MongoDB connection.
Mongo.isCausalConsistency()Indicates whether causal consistency is enabled on the connection object.
Mongo.setCausalConsistency()Enables or disables causal consistency on the connection object.
Mongo.setReadPref()Sets the read preference for the MongoDB connection.
Mongo.setSlaveOk()Allows operations on the current connection to read from secondary members.
Mongo.startSession()Starts a session on the connection object.
Mongo.watch()Opens a change stream cursor for a deploymentto report on all its non-system collections across all itsdatabases, excluding the internal admin, local, andconfig databases.
SessionThe session object.
SessionOptionsThe options object for the session.