Session
Definition
New in version 3.6.
The Session object for the connection in the mongo
shell.To instantiate a session for the connection in the mongo
shell, see Mongo.startSession()
. For more information onsessions, see Client Sessions and Causal Consistency Guarantees.
MethodDescription
Session.
getDatabase
() - Access the specified database from the session in the
mongo
shell. Session.
advanceClusterTime
({ clusterTime:, signature: { hash: , keyId: } } )- Updates the cluster time tracked by the session.
Session.
advanceOperationTime
() - Updates the operation time.
Session.
endSession
()- Ends the session.
Session.
hasEnded
()- Returns a boolean that specifies whether the session hasended.
Session.
getClusterTime
()- Returns the most recent cluster time as seen by the session.Applicable for replica sets and sharded clusters only.
Session.
getOperationTime
()- Returns the timestamp of the last acknowledged operation forthe session.
Session.
getOptions
()- Access the options for the session. For the availableoptions, see
SessionOptions
.Session.startTransaction()
Starts a multi-document transaction for the session. Fordetails, seeSession.startTransaction()
.Session.commitTransaction()
Commits the session’s transaction. For details, seeSession.commitTransaction()
.Session.abortTransaction()
Aborts the session’s transaction. For details, seeSession.abortTransaction()
.
Example
The following example starts a session on the Mongo
connection object associated with the mongo
shell’s globaldb
variable, and then uses the Session.getDatabase()
method to retrieve the database object associated with the session.
- var session = db.getMongo().startSession();
- db = session.getDatabase(db.getName());