Docs HomeMongoDB Manual

SessionOptions

On this page

Definition

SessionOptions

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

The session options available are:

OptionDescription
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 run Mongo.startSession(). You can also access the readConcern option via the following methods:
  • Session.getOptions().getReadConcern()
  • Session.getOptions().setReadConcern(<document>)
readPreferenceDocument. Specifies the read preference.
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>})
retryWritesBoolean. Enables or disables the ability to retry writes upon encountering transient network errors, such as during failovers.
To enable retry writes, start mongosh with the --retryWrites option.
You can view whether retryWrites is enabled for a session via the following method:
  • Session.getOptions().shouldRetryWrites()
writeConcernDocument. Specifies the write concern.
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>)

Verify which options are enabled for the session by running Session.getOptions().