Navigation

SessionOptions

On this page

Definition

SessionOptions()

New in version 3.6.

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

The session options available are:

Option Description
causalConsistency

Boolean. Enables or disables causal consistency for the session.

In the mongo shell, Mongo.startSession() enables causalConsistency by default. You can also explicitly set the option when you run Mongo.startSession().

You can view whether causalConsistency is enabled for the session via the following method:

  • Session.getOptions().isCausalConsistency()
readConcern

Document. Specifies the read concern.

In the mongo shell, 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

Document. Specifies the read preference.

In the mongo shell, 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

Boolean. Enables or disables the ability to retry writes upon encountering transient network errors, such as during failovers.

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

You can view whether retryWrites is enabled for a session via the following method:

  • Session.getOptions().shouldRetryWrites()
writeConcern

Document. Specifies the write concern.

In the mongo shell, 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 Native Methods  →