SessionOptions
On this page本页内容
Definition定义
SessionOptions
-
The options for asession
inmongosh
.mongosh
的session
选项。To access the要访问SessionOptions()
object, use theSession.getOptions()
method.SessionOptions()
对象,请使用Session.getOptions()
方法。The session options available are:可用的会话选项包括:Option选项Description描述causalConsistency
Boolean.布尔值。Enables or disables causal consistency for the session.启用或禁用会话的因果一致性。
You can explicitly set the option when you start a session manually:手动启动会话时,可以显式设置该选项:Session = db.getMongo().startSession( { causalConsistency: true } )
readConcern
Document.文档。Specifies the read concern.指定读取关注。
In在mongosh
, you can set the option when you runMongo.startSession()
.mongosh
中,您可以在运行Mongo.startSession()
时设置该选项。You can also access the您也可以通过以下方法访问readConcern
option via the following methods:readConcern
选项:Session.getOptions().getReadConcern()
Session.getOptions().setReadConcern(<document>)
readPreference
Document.文档。Specifies the read preference.指定读取首选项。
In在mongosh
, you can set the option when you runMongo.startSession()
.mongosh
中,您可以在运行Mongo.startSession()
时设置该选项。You can also access the您也可以通过以下方法访问readPreference
option via the following methods:readPreference
选项:Session.getOptions().getReadPreference()
Session.getOptions().setReadPreference({ mode: <string>, tags: <array>})
retryWrites
Boolean.布尔值。Enables or disables the ability to retry writes upon encountering transient network errors, such as during failovers.启用或禁用在遇到瞬时网络错误时重试写入的功能,例如在故障切换期间。
To enable retry writes, start要启用重试写入,请使用mongosh
with the--retryWrites
option.--retryWrites
选项启动mongosh
。
You can view whether您可以通过以下方法查看是否为会话启用了retryWrites
is enabled for a session via the following method:retryWrites
:Session.getOptions().shouldRetryWrites()
writeConcern
Document.文档。Specifies the write concern.指定写入关注。
In在mongosh
, you can set the options when you runMongo.startSession()
.mongosh
中,您可以在运行Mongo.startSession()
时设置选项。You can also access the您还可以通过以下方法访问writeConcern
option via the following methods:writeConcern
选项:Session.getOptions().getWriteConcern()
Session.getOptions().setWriteConcern(<document>)
Verify which options are enabled for the session by running 通过运行Session.getOptions()
.Session.getOptions()
验证为会话启用了哪些选项。