文档菜单
文档首页
/
MongoDB 手册
/ / /

会话选项

本页面

  • 定义
  • 兼容性
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({模式: <字符串>, 标签: <数组>})

retryWrites

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

要启用重试写操作,使用带有 mongosh--retryWrites 选项启动。

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

  • Session.getOptions().shouldRetryWrites()

writeConcern

文档。指定 写关注。

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

  • Session.getOptions().getWriteConcern()

  • Session.getOptions().setWriteConcern(<文档>)

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

此方法在以下环境中托管的应用程序中可用

返回

Session.withTransaction()