Docs Menu

読み取り保証 (read concern) "snapshot"

バージョン 5.0 での変更

読み取り保証 "snapshot" を指定したクエリでは、直近の特定の点のシャード全体に表示れる、過半数のコミット済みデータが返されます。読み取り保証 "snapshot" は、トランザクションが書込み保証 "majority" でコミットされた場合にのみ保証を提供します。

読み取り保証(read concern) "snapshot" is available for multi-document transactions, 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, upon transaction commit with write concern "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, upon transaction commit with write concern "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.

Outside of multi-document transactions, read concern "snapshot" is available on primaries and secondaries for the following read operations:

All other read commands prohibit "snapshot".

For a list of all operations that accept read concerns, see 読み取り保証をサポートする操作.

Multi-document transactions support read concern "snapshot" as well as "local", and "majority".

注意

読み取り保証 (read concern) は、個々の操作レベルではなく、トランザクション レベルで設定します。トランザクションに読み取り保証 (read concern) を設定するには、「トランザクションと読み取り保証 (read concern)」を参照してください。

バージョン 5.0 で追加

Outside of multi-document transactions, reads with read concern "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 performs the request based on the data available at time T.

You can obtain the operationTime or clusterTime of an operation from the response of db.runCommand() or from the Session() object.

The following command performs a find operation with read concern "snapshot" and specifies that the operation should read data from the snapshot at cluster time Timestamp(1613577600, 1).

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

If the parameter atClusterTime is not supplied, the mongos, or in single member replica sets the mongod, selects the timestamp of the latest majority-committed snapshot as the atClusterTime and returns it to the client.

Outside of transactions, "snapshot" reads are guaranteed to read from majority-committed data.

  • The allowed values for atClusterTime depend on the minSnapshotHistoryWindowInSeconds parameter. minSnapshotHistoryWindowInSeconds is the minimum time window in seconds for which the storage engine keeps the snapshot history. If you specify an atClusterTime value older than the oldest snapshot retained according to minSnapshotHistoryWindowInSeconds, mongod returns an error.

  • If you perform a read operation with "snapshot" against a delayed replica set member, the returned majority-committed data could be stale.

  • It is not possible to specify atClusterTime for "snapshot" inside of causally consistent sessions.

Starting in MongoDB 8.0, you can use read concern "snapshot" on capped collections.