SessionOptions
On this page本页内容
Definition定义
SessionOptions-
The options for asessioninmongosh.mongosh的session选项。To access the要访问SessionOptions()object, use theSession.getOptions()method.SessionOptions()对象,请使用Session.getOptions()方法。The session options available are:可用的会话选项包括:Option选项Description描述causalConsistencyBoolean.布尔值。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 } )
readConcernDocument.文档。Specifies the read concern.指定读取关注。
In在mongosh, you can set the option when you runMongo.startSession().mongosh中,您可以在运行Mongo.startSession()时设置该选项。You can also access the您也可以通过以下方法访问readConcernoption via the following methods:readConcern选项:Session.getOptions().getReadConcern()Session.getOptions().setReadConcern(<document>)
readPreferenceDocument.文档。Specifies the read preference.指定读取首选项。
In在mongosh, you can set the option when you runMongo.startSession().mongosh中,您可以在运行Mongo.startSession()时设置该选项。You can also access the您也可以通过以下方法访问readPreferenceoption via the following methods:readPreference选项:Session.getOptions().getReadPreference()Session.getOptions().setReadPreference({ mode: <string>, tags: <array>})
retryWritesBoolean.布尔值。Enables or disables the ability to retry writes upon encountering transient network errors, such as during failovers.启用或禁用在遇到瞬时网络错误时重试写入的功能,例如在故障切换期间。
To enable retry writes, start要启用重试写入,请使用mongoshwith the--retryWritesoption.--retryWrites选项启动mongosh。
You can view whether您可以通过以下方法查看是否为会话启用了retryWritesis enabled for a session via the following method:retryWrites:Session.getOptions().shouldRetryWrites()
writeConcernDocument.文档。Specifies the write concern.指定写入关注。
In在mongosh, you can set the options when you runMongo.startSession().mongosh中,您可以在运行Mongo.startSession()时设置选项。You can also access the您还可以通过以下方法访问writeConcernoption 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()验证为会话启用了哪些选项。