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

# Read Concern `"snapshot"`

**Changed in version 5.0**

A query with read concern `"snapshot"` returns majority-committed data as it appears across shards from a specific single point in time in the recent past. Read concern `"snapshot"` provides its guarantees only if the transaction commits with write concern [`"majority"`.](https://www.mongodb.com/docs/manual/reference/write-concern.md#mongodb-writeconcern-writeconcern.-majority-)

Read concern `"snapshot"` is available for [multi-document transactions](https://www.mongodb.com/docs/manual/core/transactions.md), and starting in MongoDB 5.0, certain read operations outside of multi-document transactions.

- If the transaction is not part of a [causally consistent session](https://www.mongodb.com/docs/manual/core/read-isolation-consistency-recency.md#std-label-sessions), upon transaction commit with write concern [`"majority"`](https://www.mongodb.com/docs/manual/reference/write-concern.md#mongodb-writeconcern-writeconcern.-majority-), the transaction operations are guaranteed to have read from a snapshot of majority-committed data.

- If the transaction is part of a [causally consistent session](https://www.mongodb.com/docs/manual/core/read-isolation-consistency-recency.md#std-label-sessions), upon transaction commit with write concern [`"majority"`](https://www.mongodb.com/docs/manual/reference/write-concern.md#mongodb-writeconcern-writeconcern.-majority-), the transaction operations are guaranteed to have read from a snapshot of majority-committed data that provides causal consistency with the operation immediately preceding the transaction start.

**Important:**

A `"snapshot"` read can only be performed within the time period specified by [`minSnapshotHistoryWindowInSeconds`](https://www.mongodb.com/docs/manual/reference/parameters.md#mongodb-parameter-param.minSnapshotHistoryWindowInSeconds). A read operation that lasts longer than [`minSnapshotHistoryWindowInSeconds`](https://www.mongodb.com/docs/manual/reference/parameters.md#mongodb-parameter-param.minSnapshotHistoryWindowInSeconds) may terminate.

Outside of multi-document transactions, read concern [`"snapshot"`](https://www.mongodb.com/docs/manual/reference/read-concern-snapshot.md#mongodb-readconcern-readconcern.-snapshot-) is available on primaries and secondaries for the following read operations:

- [`find`](https://www.mongodb.com/docs/manual/reference/command/find.md#mongodb-dbcommand-dbcmd.find)

- [`aggregate`](https://www.mongodb.com/docs/manual/reference/command/aggregate.md#mongodb-dbcommand-dbcmd.aggregate)

- [`distinct`](https://www.mongodb.com/docs/manual/reference/command/distinct.md#mongodb-dbcommand-dbcmd.distinct) (on unsharded collections)

All other read commands prohibit [`"snapshot"`.](https://www.mongodb.com/docs/manual/reference/read-concern-snapshot.md#mongodb-readconcern-readconcern.-snapshot-)

## Operations

For a list of all operations that accept read concerns, see [Operations That Support Read Concern.](https://www.mongodb.com/docs/manual/reference/read-concern.md#std-label-read-concern-operations)

## Read Concern and Transactions

Multi-document transactions support read concern [`"snapshot"`](https://www.mongodb.com/docs/manual/reference/read-concern-snapshot.md#mongodb-readconcern-readconcern.-snapshot-) as well as [`"local"`](https://www.mongodb.com/docs/manual/reference/read-concern-local.md#mongodb-readconcern-readconcern.-local-), and [`"majority"`.](https://www.mongodb.com/docs/manual/reference/read-concern-majority.md#mongodb-readconcern-readconcern.-majority-)

**Note:**

You set the read concern at the transaction level, not at the individual operation level. To set the read concern for transactions, see [Transactions and Read Concern.](https://www.mongodb.com/docs/manual/core/transactions.md#std-label-transactions-read-concern)

## Read Concern and `atClusterTime`

Outside of multi-document transactions, reads with read concern [`"snapshot"`](https://www.mongodb.com/docs/manual/reference/read-concern-snapshot.md#mongodb-readconcern-readconcern.-snapshot-) support the optional parameter `atClusterTime`. The parameter `atClusterTime` allows you to specify the timestamp for the read. To satisfy a read request with a specified `atClusterTime` of T, the [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) performs the request based on the data available at time T. If the [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) has not yet reached time T in its oplog, it waits to service the request.

**Tip:**

If you have reads directed at lagging replica set members, you can use `maxTimeMS` to bound the wait time for reads with a specified `atClusterTime`. `maxTimeMS` ensures that the operation does not block indefinitely and instead returns an error if the `mongod` does not reach the specified `atClusterTime` in time.

You can obtain the `operationTime` or `clusterTime` of an operation from the response of [`db.runCommand()`](https://www.mongodb.com/docs/manual/reference/method/db.runCommand.md#mongodb-method-db.runCommand) or from the [`Session()`](https://www.mongodb.com/docs/manual/reference/method/Session.md#mongodb-method-Session) object.

The following command performs a find operation with read concern [`"snapshot"`](https://www.mongodb.com/docs/manual/reference/read-concern-snapshot.md#mongodb-readconcern-readconcern.-snapshot-) and specifies that the operation should read data from the snapshot at cluster time `Timestamp(1613577600, 1)`.

```javascript
db.runCommand( {
    find: "restaurants",
    filter: { _id: 5 },
    readConcern: {
        level: "snapshot",
        atClusterTime: Timestamp(1613577600, 1)
    },
} )
```

If the parameter `atClusterTime` is not supplied, the [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos), or in single member replica sets the [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod), selects the timestamp of the latest majority-committed snapshot as the `atClusterTime` and returns it to the client.

Outside of transactions, [`"snapshot"`](https://www.mongodb.com/docs/manual/reference/read-concern-snapshot.md#mongodb-readconcern-readconcern.-snapshot-) reads are guaranteed to read from majority-committed data.

### `atClusterTime` Considerations and Behavior

- The allowed values for `atClusterTime` depend on the [`minSnapshotHistoryWindowInSeconds`](https://www.mongodb.com/docs/manual/reference/parameters.md#mongodb-parameter-param.minSnapshotHistoryWindowInSeconds) parameter. `minSnapshotHistoryWindowInSeconds` is the minimum time window in seconds for which the storage engine keeps the snapshot history. If you specify an [atClusterTime](https://www.mongodb.com/docs/manual/reference/read-concern-snapshot.md#std-label-atClusterTime) value older than the oldest snapshot retained according to `minSnapshotHistoryWindowInSeconds`, [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) returns an error.

- If you perform a read operation with [`"snapshot"`](https://www.mongodb.com/docs/manual/reference/read-concern-snapshot.md#mongodb-readconcern-readconcern.-snapshot-) without specifying `atClusterTime` against a delayed replica set member, the returned majority-committed data could be stale. If you specify `atClusterTime`, the [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) waits for the specified timestamp instead of returning stale data, though the read may block or time out.

- It is not possible to specify `atClusterTime` for [`"snapshot"`](https://www.mongodb.com/docs/manual/reference/read-concern-snapshot.md#mongodb-readconcern-readconcern.-snapshot-) inside of [causally consistent sessions.](https://www.mongodb.com/docs/manual/core/read-isolation-consistency-recency.md#std-label-sessions)

## Read Concern on Capped Collections

Starting in MongoDB 8.0, you can use read concern [`"snapshot"`](https://www.mongodb.com/docs/manual/reference/read-concern-snapshot.md#mongodb-readconcern-readconcern.-snapshot-) on [capped](https://www.mongodb.com/docs/manual/core/capped-collections.md#std-label-manual-capped-collection) collections.
