> This page location: /docs.md > /docs/development.md > /docs/manual/reference/method.md

> For the complete MongoDB documentation index, see www.mongodb.com/docs/llms.txt

# Session

## Definition

The Session object for the connection in [`mongosh`](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh). To instantiate a session for the connection in [`mongosh`](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh), see [`Mongo.startSession()`](https://www.mongodb.com/docs/manual/reference/method/mongo.startsession.md#mongodb-method-Mongo.startSession). For more information on sessions, see [Client Sessions and Causal Consistency Guarantees.](https://www.mongodb.com/docs/manual/core/read-isolation-consistency-recency.md#std-label-sessions)

### General Session Methods

| Method | Description |
| --- | --- |
|  | Updates the cluster time tracked by the session. This method has the following parameters: `Session.advanceClusterTime( {
   clusterTime: <timestamp>,
   signature:
      { hash: <BinData>, keyId: <NumberLong> }
} )` |
|  | Updates the operation time. |
|  | Performs multiple write operations across databases and collections within the session. Requires MongoDB 8.0 or later. For parameters and return value details, see [`Mongo.bulkWrite()`.](https://www.mongodb.com/docs/manual/reference/method/mongo.bulkwrite.md#mongodb-method-Mongo.bulkWrite) |
|  | 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`.](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh) |
|  | Access the options for the session. For the available options, see [`SessionOptions()`.](https://www.mongodb.com/docs/manual/reference/method/sessionoptions.md#mongodb-method-SessionOptions) |
|  | 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 |
| --- | --- |
| [`Session.abortTransaction()`](https://www.mongodb.com/docs/manual/reference/method/session.aborttransaction.md#mongodb-method-Session.abortTransaction) | Aborts the session's transaction. For details, see [`Session.abortTransaction()`.](https://www.mongodb.com/docs/manual/reference/method/session.aborttransaction.md#mongodb-method-Session.abortTransaction) |
| [`Session.commitTransaction()`](https://www.mongodb.com/docs/manual/reference/method/session.committransaction.md#mongodb-method-Session.commitTransaction) | Commits the session's transaction. For details, see [`Session.commitTransaction()`.](https://www.mongodb.com/docs/manual/reference/method/session.committransaction.md#mongodb-method-Session.commitTransaction) |
| [`Session.startTransaction()`](https://www.mongodb.com/docs/manual/reference/method/session.starttransaction.md#mongodb-method-Session.startTransaction) | Starts a multi-document transaction for the session. For details, see [`Session.startTransaction()`.](https://www.mongodb.com/docs/manual/reference/method/session.starttransaction.md#mongodb-method-Session.startTransaction) |
| [`Session.withTransaction()`](https://www.mongodb.com/docs/manual/reference/method/session.withtransaction.md#mongodb-method-Session.withTransaction) | Runs a specified lambda function within a transaction. For details, see [`Session.withTransaction()`.](https://www.mongodb.com/docs/manual/reference/method/session.withtransaction.md#mongodb-method-Session.withTransaction) |

## Example

The following example starts a session on the [`Mongo()`](https://www.mongodb.com/docs/manual/reference/method/mongo.md#mongodb-method-Mongo) connection object associated with [`mongosh`](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh)'s global `db` variable, and then uses the [`Session.getDatabase()`](https://www.mongodb.com/docs/manual/reference/method/session.md#mongodb-method-Session.getDatabase) method to retrieve the database object associated with the session.

```javascript
var session = db.getMongo().startSession();
db = session.getDatabase(db.getName());
```
