Docs HomeMongoDB Manual

Connection Methods连接方法

Note

For details on a specific method, including syntax and examples, click on the link to the method's reference page.有关特定方法的详细信息,包括语法和示例,请单击该方法参考页的链接。

Name名称Description描述
connect()Connects to a MongoDB instance and to a specified database on that instance.连接到MongoDB实例和该实例上的指定数据库。
Mongo()Creates a new connection object.创建新的连接对象。
Mongo.getDB()Returns a database object.返回数据库对象。
Mongo.getDBNames()Returns a list of databases.返回数据库列表。
Mongo.getDBs()Returns a document with a list of databases and metadata.返回包含数据库和元数据列表的文档。
Mongo.getReadPrefMode()Returns the current read preference mode for the MongoDB connection.返回MongoDB连接的当前读取首选模式。
Mongo.getReadPrefTagSet()Returns the read preference tag set for the MongoDB connection.返回为MongoDB连接设置的读取首选项标记。
Mongo.getWriteConcern()Returns the write concern for the connection object.返回连接对象的写入关注
Mongo.setCausalConsistency()Enables or disables causal consistency on the connection object.启用或禁用连接对象上的因果一致性。
Mongo.setReadPref()Sets the read preference for the MongoDB connection.设置MongoDB连接的读取首选项
Mongo.setWriteConcern()Sets the write concern for the connection object.设置连接对象的写入关注
Mongo.startSession()Starts a session on the connection object.在连接对象上启动会话。
Mongo.watch()Opens a change stream cursor for a deployment to report on all its non-system collections across all its databases, excluding the internal admin, local, and config databases.打开部署的更改流游标,以报告其所有数据库中的所有非system集合,不包括内部admin数据库、local数据库和local数据库。
Session()The session object.会话对象。
SessionOptions()The options object for the session.会话的选项对象。