Definition
SessionOptionsThe options for a
sessioninmongosh. To access theSessionOptions()object, use theSession.getOptions()method.The session options available are:
OptionDescriptioncausalConsistencyBoolean. 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 runMongo.startSession(). You can also access thereadConcernoption 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 runMongo.startSession(). You can also access thereadPreferenceoption 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
mongoshwith the--retryWritesoption.You can view whether
retryWritesis 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 runMongo.startSession(). You can also access thewriteConcernoption via the following methods:Session.getOptions().getWriteConcern()Session.getOptions().setWriteConcern(<document>)
Verify which options are enabled for the session by running Session.getOptions().
Compatibility
This method is available in deployments hosted in the following environments:
MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
MongoDB Enterprise: The subscription-based, self-managed version of MongoDB
MongoDB Community: The source-available, free-to-use, and self-managed version of MongoDB