> 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

# Mongo.startSession() (mongosh method)

## Definition

Starts a [session](https://www.mongodb.com/docs/manual/reference/server-sessions.md#std-label-server-sessions) for the connection. [`mongosh`](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh) assigns the session ID to commands associated with the session.

**Important: mongosh Method**

This page documents a [`mongosh`](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh) method. This is *not* the documentation for database commands or language-specific drivers, such as Node.js.

For the database command, see the [`startSession`](https://www.mongodb.com/docs/manual/reference/command/startsession.md#mongodb-dbcommand-dbcmd.startSession) command.

For MongoDB API drivers, refer to the language-specific [MongoDB driver documentation.](https://www.mongodb.com/docs/drivers/)

A session can only be used with the `MongoClient` object that created the session. A single session cannot be used concurrently. Operations that use a single session must be run sequentially.

The [`startSession()`](https://www.mongodb.com/docs/manual/reference/method/mongo.startsession.md#mongodb-method-Mongo.startSession) method can take a document with session options. The options available are:

| Field | Description |
| --- | --- |
| causalConsistency | Boolean. Enables or disables [causal consistency](https://www.mongodb.com/docs/manual/core/read-isolation-consistency-recency.md#std-label-causal-consistency) for the session. [`Mongo.startSession()`](https://www.mongodb.com/docs/manual/reference/method/mongo.startsession.md#mongodb-method-Mongo.startSession) enables `causalConsistency` by default. Mutually exclusive with `snapshot`. After starting a session, you cannot modify its `causalConsistency` setting. The session may have causal consistency enabled even though the [`Mongo()`](https://www.mongodb.com/docs/manual/reference/method/mongo.md#mongodb-method-Mongo) connection object may have causal consistency disabled or vice versa. To set causal consistency on the connection object, see [`Mongo.setCausalConsistency()`.](https://www.mongodb.com/docs/manual/reference/method/mongo.setcausalconsistency.md#mongodb-method-Mongo.setCausalConsistency) |
| readConcern | Document. Specifies the [read concern.](https://www.mongodb.com/docs/manual/reference/read-concern.md#std-label-read-concern) To modify the setting after starting a session, see [`Session.getOptions().setReadConcern()`.](https://www.mongodb.com/docs/manual/reference/method/session.md#mongodb-method-Session.getOptions) |
| readPreference | Document. Specifies the [read preference.](https://www.mongodb.com/docs/manual/core/read-preference.md#std-label-read-preference) The readPreference document contains the `mode` field and the optional `tags` field: `{ mode: <string>, tags: <array> }` To modify the setting after starting a session, see [`Session.getOptions().setReadPreference()`.](https://www.mongodb.com/docs/manual/reference/method/session.md#mongodb-method-Session.getOptions) |
| retryWrites | Boolean. Enables or disables the ability to retry writes upon encountering transient network errors. If you start [`mongosh`](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh) with the [`--retryWrites`](https://www.mongodb.com/docs/mongodb-shell/reference/options.md#std-option-mongosh.--retryWrites) option, `retryWrites` is enabled by default for [`Mongo.startSession()`.](https://www.mongodb.com/docs/manual/reference/method/mongo.startsession.md#mongodb-method-Mongo.startSession) After starting a session, you cannot modify its `retryWrites` setting. |
| snapshot | Boolean. Enables [snapshot reads](https://www.mongodb.com/docs/manual/reference/read-concern-snapshot.md#std-label-read-concern-snapshot) for the session for MongoDB 5.0+ deployments. Mutually exclusive with `causalConsistency`. |
| writeConcern | Document. Specifies the [write concern.](https://www.mongodb.com/docs/manual/reference/write-concern.md#std-label-write-concern) To modify the setting after starting a session, see [`Session.getOptions().setWriteConcern()`.](https://www.mongodb.com/docs/manual/reference/method/session.md#mongodb-method-Session.getOptions) |

## Compatibility

This method is available in deployments hosted in the following environments:

- [MongoDB Atlas](https://www.mongodb.com/docs/atlas): The fully managed service for MongoDB deployments in the cloud

**Note:**

This command is supported in all MongoDB Atlas clusters. For information on Atlas support for all commands, see [Unsupported Commands.](https://www.mongodb.com/docs/atlas/unsupported-commands/)

- [MongoDB Enterprise](https://www.mongodb.com/docs/manual/administration/install-enterprise.md#std-label-install-mdb-enterprise): The subscription-based, self-managed version of MongoDB

- [MongoDB Community](https://www.mongodb.com/docs/manual/administration/install-community.md#std-label-install-mdb-community-edition): The source-available, free-to-use, and self-managed version of MongoDB

## Examples

The following starts a session with causal consistency and retryable writes enabled 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:

```javascript
db = db.getMongo().startSession({retryWrites: true, causalConsistency: true}).getDatabase(db.getName());
```
