Definition定义
SessionOptionsThe options for asessioninmongosh.mongoshsession的选项。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(). You can also access thereadConcernoption via the following methods:mongosh中,您可以在运行Mongo.startSession()时设置该选项。您还可以通过以下方法访问readConcern选项:Session.getOptions().getReadConcern()Session.getOptions().setReadConcern(<document>)
readPreferenceDocument. Specifies the read preference.文档。指定读取首选项。In在mongosh, you can set the option when you runMongo.startSession(). You can also access thereadPreferenceoption via the following methods:mongosh中,您可以在运行Mongo.startSession()时设置该选项。您还可以通过以下方法访问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(). You can also access thewriteConcernoption via the following methods:mongosh中,您可以在运行Mongo.startSession()时设置选项。您还可以通过以下方法访问writeConcern选项:Session.getOptions().getWriteConcern()Session.getOptions().setWriteConcern(<document>)
Verify which options are enabled for the session by running 通过运行Session.getOptions().Session.getOptions()验证会话启用了哪些选项。
Compatibility兼容性
This method is available in deployments hosted in the following environments:此方法在以下环境中托管的部署中可用:
- MongoDB Atlas
: The fully managed service for MongoDB deployments in the cloud:云中MongoDB部署的完全托管服务
- MongoDB Enterprise
: The subscription-based, self-managed version of MongoDB:MongoDB的基于订阅的自我管理版本 - MongoDB Community
: The source-available, free-to-use, and self-managed version of MongoDB:MongoDB的源代码可用、免费使用和自我管理版本