定义
SessionOptionsThe options for a
sessioninmongosh. To access theSessionOptions()object, use theSession.getOptions()method.可用的会话选项有:
选项说明causalConsistency布尔值。为会话启用或禁用因果一致性。
您可以在手动启动会话时显式设置该选项:
Session = db.getMongo().startSession( { causalConsistency: true } )
readConcern文档。指定读关注。
In
mongosh, you can set the option when you runMongo.startSession(). You can also access thereadConcernoption via the following methods:Session.getOptions().getReadConcern()Session.getOptions().setReadConcern(<document>)
readPreference文档。指定读取偏好。
In
mongosh, you can set the option when you runMongo.startSession(). You can also access thereadPreferenceoption via the following methods:Session.getOptions().getReadPreference()Session.getOptions().setReadPreference({ mode: <string>, tags: <array>})
retryWrites布尔值。 启用或禁用在遇到暂时性网络错误时(例如在故障转移期间)重试写入的能力。
To enable retry writes, start
mongoshwith the--retryWritesoption.您可以通过以下方法查看会话是否启用了
retryWrites:Session.getOptions().shouldRetryWrites()
writeConcern文档。指定写关注。
In
mongosh, you can set the options when you runMongo.startSession(). You can also access thewriteConcernoption via the following methods:Session.getOptions().getWriteConcern()Session.getOptions().setWriteConcern(<document>)
通过运行Session.getOptions()验证为会话启用了哪些选项。
兼容性
此方法可用于以下环境中托管的部署:
- MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
MongoDB Enterprise:基于订阅、自我管理的 MongoDB 版本
MongoDB Community:源代码可用、免费使用且可自行管理的 MongoDB 版本