“文档” 菜单
文档首页
/
MongoDB Manual
/ / /

SessionOptions

在此页面上

  • 定义
SessionOptions

sessionmongosh SessionOptions()的选项。要访问Session.getOptions() 对象,请使用 方法。

可用的会话选项有:

选项
说明
causalConsistency

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

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

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

readConcern

文档。指定读关注

mongosh 中,您可以在运行 Mongo.startSession() 时设置该选项。您还可以通过以下方法使用 readConcern 选项:

  • Session.getOptions().getReadConcern()

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

readPreference

文档。指定读取偏好

mongosh 中,您可以在运行 Mongo.startSession() 时设置该选项。您还可以通过以下方法使用 readPreference 选项:

  • Session.getOptions().getReadPreference()

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

retryWrites

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

要启用写入重试功能,请使用 选项启动mongosh --retryWrites

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

  • Session.getOptions().shouldRetryWrites()

writeConcern

文档。指定写关注

mongosh中,您可以在运行Mongo.startSession()时设置选项。您还可以通过以下方法访问writeConcern选项:

  • Session.getOptions().getWriteConcern()

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

通过运行Session.getOptions()验证为会话启用了哪些选项。

← Session.withTransaction()

在此页面上