On this page本页内容
Mongo.startSession(<options>) Starts a session for the connection. 为连接启动会话。mongosh assigns the session id to commands associated with the session.将会话id分配给与会话关联的命令。
The startSession() method can take a document with session options. startSession()方法可以获取带有会话选项的文档。The options available are:可用选项包括:
causalConsistency |
|
readConcern |
|
readPreference |
{ mode: <string>, tags: <array> }
|
retryWrites |
|
writeConcern |
|
The following starts a session with causal consistency and retryable writes enabled on the 以下内容启动了一个会话,该会话在与Mongo() connection object associated with mongosh's global db variable:mongosh的全局db变量关联的Mongo()连接对象上启用了因果一致性和可重试写入:
db = db.getMongo().startSession({retryWrites: true, causalConsistency: true}).getDatabase(db.getName());