- Reference >
mongoshMethods >- Connection Methods >
- Mongo.startSession()
Mongo.startSession()¶
On this page
Definition¶
-
Mongo.startSession(<options>)¶ Starts a session for the connection.
mongoshassigns the session id to commands associated with the session.The
startSession()method can take a document with session options. The options available are:Field Description causalConsistency Boolean. Enables or disables causal consistency for the session.
Mongo.startSession()enablescausalConsistencyby default.After starting a session, you cannot modify its
causalConsistencysetting.Note
The session may have causal consistency enabled even though the
Mongoconnection object may have causal consistency disabled or vice versa. To set causal consistency on the connection object, seeMongo.setCausalConsistency().readConcern Document. Specifies the read concern.
To modify the setting after starting a session, see
Session.getOptions().setReadConcern().readPreference Document. Specifies the read preference.
The readPreference document contains the
modefield and the optionaltagsfield:To modify the setting after starting a session, see
Session.getOptions().setReadPreference().retryWrites Boolean. Enables or disables the ability to retry writes upon encountering transient network errors.
If you start
mongoshwith the--retryWritesoption,retryWritesis enabled by default forMongo.startSession().After starting a session, you cannot modify its
retryWritessetting.writeConcern Document. Specifies the write concern.
To modify the setting after starting a session, see
Session.getOptions().setWriteConcern().