对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

会话

Session

The Session object for the connection in mongosh. To instantiate a session for the connection in mongosh, see Mongo.startSession(). For more information on sessions, see Client Sessions and Causal Consistency Guarantees.

方法

说明

Session.advanceClusterTime()

更新会话跟踪的集群时间。

此方法具有以下参数:

Session.advanceClusterTime( {
clusterTime: <timestamp>,
signature:
{ hash: <BinData>, keyId: <NumberLong> }
} )
Session.advanceOperationTime(<timestamp>)

更新操作时间。

Session.bulkWrite(operations, options)

在会话中跨数据库和集合执行多个写入操作。需要 MongoDB 8.0 或更高版本。有关参数和返回值详情,请参阅 Mongo.bulkWrite()

Session.endSession()

结束会话。

Session.getClusterTime()

返回会话读到的最新集群时间。仅适用于副本集和分片集群。

Session.getDatabase(<database>)

Access the specified database from the session in mongosh.

Session.getOptions()

访问会话选项。 有关可用选项,请参阅SessionOptions()

Session.getOperationTime()

返回会话最后一次确认操作的时间戳。

Session.hasEnded()

返回一个布尔值,指明会话是否已结束。

方法

说明

终止会话事务。有关详细信息,请参阅 Session.abortTransaction()

提交会话的事务。有关详细信息,请参阅 Session.commitTransaction()

为会话启动多文档事务。有关详细信息,请参阅 Session.startTransaction()

在事务中运行指定的 lambda 函数。有关详细信息,请参阅 Session.withTransaction()Session.withTransaction()

The following example starts a session on the Mongo() connection object associated with mongosh's global db variable, and then uses the Session.getDatabase() method to retrieve the database object associated with the session.

var session = db.getMongo().startSession();
db = session.getDatabase(db.getName());
给本页内容打分

在此页面上