定义
SessionThe Session object for the connection in
mongosh. To instantiate a session for the connection inmongosh, seeMongo.startSession(). For more information on sessions, see Client Sessions and Causal Consistency Guarantees.常规会话方法
方法
说明
更新会话跟踪的集群时间。
此方法具有以下参数:
Session.advanceClusterTime( { clusterTime: <timestamp>, signature: { hash: <BinData>, keyId: <NumberLong> } } ) 更新操作时间。
在会话中跨数据库和集合执行多个写入操作。需要 MongoDB 8.0 或更高版本。有关参数和返回值详情,请参阅
Mongo.bulkWrite()。结束会话。
返回会话读到的最新集群时间。仅适用于副本集和分片集群。
Access the specified database from the session in
mongosh.访问会话选项。 有关可用选项,请参阅
SessionOptions()。返回会话最后一次确认操作的时间戳。
返回一个布尔值,指明会话是否已结束。
事务的会话方法
方法
说明
终止会话事务。有关详细信息,请参阅
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());