对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

SessionOptions

SessionOptions

The options for a session in mongosh. To access the SessionOptions() object, use the Session.getOptions() method.

可用的会话选项有:

选项
说明

causalConsistency

布尔值。为会话启用或禁用因果一致性。

您可以在手动启动会话时显式设置该选项:

  • Session = db.getMongo().startSession( { causalConsistency: true } )

readConcern

文档。指定读关注。

In mongosh, you can set the option when you run Mongo.startSession(). You can also access the readConcern option via the following methods:

  • Session.getOptions().getReadConcern()

  • Session.getOptions().setReadConcern(<document>)

readPreference

文档。指定读取偏好。

In mongosh, you can set the option when you run Mongo.startSession(). You can also access the readPreference option via the following methods:

  • Session.getOptions().getReadPreference()

  • Session.getOptions().setReadPreference({ mode: <string>, tags: <array>})

retryWrites

布尔值。 启用或禁用在遇到暂时性网络错误时(例如在故障转移期间)重试写入的能力。

To enable retry writes, start mongosh with the --retryWrites option.

您可以通过以下方法查看会话是否启用了retryWrites :

  • Session.getOptions().shouldRetryWrites()

writeConcern

文档。指定写关注。

In mongosh, you can set the options when you run Mongo.startSession(). You can also access the writeConcern option 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
给本页内容打分

在此页面上