New in version 3.6.
The Session object for the connection in
mongosh. To instantiate a session for the connection in
Mongo.startSession(). For more information on sessions, see Client Sessions and Causal Consistency Guarantees.MethodDescriptionUpdates the cluster time tracked by the session.Updates the operation time.Ends the session.Returns the most recent cluster time as seen by the session. Applicable for replica sets and sharded clusters only.Access the specified database from the session in
mongosh.Access the options for the session. For the available options, see
SessionOptions().Returns the timestamp of the last acknowledged operation for the session.Returns a boolean that specifies whether the session has ended.MethodDescriptionAborts the session's transaction. For details, see
Session.abortTransaction().Commits the session's transaction. For details, see
Session.commitTransaction().Starts a multi-document transaction for the session. For details, see
Session.startTransaction().Runs a specified lambda function within a transaction. For details, see
The following example starts a session on the
connection object associated with
db variable, and then uses the
method to retrieve the database object associated with the session.
var session = db.getMongo().startSession(); db = session.getDatabase(db.getName());