SessionOptions
Definition
New in version 3.6.
The options for a session
in themongo
shell. To access the SessionOptions
object, use the Session.getOptions()
method.
The session options available are:
OptionDescriptioncausalConsistency
Boolean. Enables or disables causal consistency for the session.
In the mongo
shell, Mongo.startSession()
enables causalConsistency
by default. You can alsoexplicitly set the option when you runMongo.startSession()
.
You can view whether causalConsistency
is enabled for thesession via the following method:
Session.getOptions().isCausalConsistency()
readConcern
Document. Specifies the read concern.
In the mongo
shell, you can set the option whenyou run Mongo.startSession()
. You can also accessthe 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 optionwhen you run Mongo.startSession()
. You can alsoaccess the readPreference
option via the followingmethods:
Session.getOptions().getReadPreference()
Session.getOptions().setReadPreference({ mode: <string>, tags: <array>})
retryWrites
Boolean. Enables or disables the ability to retry writes uponencountering transient network errors, such as duringfailovers.
To enable retry writes, start the mongo
shellwith the —retryWrites
option.
You can view whether retryWrites
is enabled for a sessionvia the following method:
Session.getOptions().shouldRetryWrites()
writeConcern
Document. Specifies the write concern.
In the mongo
shell, you can set the optionswhen you run Mongo.startSession()
. You can alsoaccess the writeConcern
option via the following methods:
Session.getOptions().getWriteConcern()
Session.getOptions().setWriteConcern(<document>)