mongosh
.
To instantiate a session for the connection in
mongosh
, see Mongo.startSession()
. For more
information on sessions, see Client Sessions and Causal Consistency Guarantees.General Session Methods
Method | Description | |||||
Updates the cluster time tracked by the session. This method has the following parameters:
| ||||||
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 | ||||||
Access the options for the session. For the available
options, see | ||||||
Returns the timestamp of the last acknowledged operation for the session. | ||||||
Returns a boolean that specifies whether the session has ended. |
Session Methods for Transactions
Method | Description |
Aborts the session's transaction. For details, see
| |
Commits the session's transaction. For details, see
| |
Starts a multi-document transaction for the session. For
details, see | |
Runs a specified lambda function within a transaction. For
details, see |
Example
The following example starts a session on the Mongo()
connection object associated with mongosh
's global
db
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());