AI エージェント向け: ドキュメントインデックスは https://www.mongodb.com/ja-jp/docs/llms.txt で利用できます。すべてのページの markdown バージョンは、いずれかの URL パスに .md を追加することで利用できます。
Docs Menu

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

バージョン5.0で変更。

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

読み取り保証"snapshot"は、マルチドキュメントトランザクションと MongoDB 5.0 以降では、マルチドキュメントトランザクション外の特定の読み取り操作で使用できます。

  • トランザクションが因果関係がコンシステントなセッションの一部でない場合、書込み保証"majority"によるトランザクションのコミット時に、トランザクション操作は、大多数がコミットされたデータのスナップショットから読み取られることが保証されます。

  • トランザクションが因果関係がコンシステントなセッションの一部である場合、書込み保証"majority"によるトランザクションのコミット時に、トランザクション操作は、トランザクションの開始直前の操作との因果整合性を提供する、大多数がコミットされたデータのスナップショットから読み取られることが保証されます。

重要

"snapshot" 読み取りは、minSnapshotHistoryWindowInSeconds で指定された期間内にのみ実行できます。minSnapshotHistoryWindowInSeconds より長く続く読み取り操作が終了する可能性があります。

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".

読み取り保証を受け入れるすべての操作のリストについては、「読み取り保証をサポートする操作 」を参照してください。

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

注意

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

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. If the mongod has not yet reached time T in its oplog, it waits to service the request.

Tip

レプリカセットのノードの延遅に向けて読み取りが行われる場合、maxTimeMS を使用して、指定された atClusterTime で読み取りの待機時間に上限を設定できます。maxTimeMS により、操作が無期限にブロックされることはなく、代わりに mongod が指定された atClusterTime に時間内に達しない場合はエラーが返されます。

操作のoperationTimeまたはclusterTimeは、 db.runCommand()の応答またはSession()オブジェクトから取得できます。

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)
},
} )

パラメータatClusterTimeが指定されていない場合、 mongos 、または単一ノード レプリカセットではmongodは、最新の 過半数がコミットしたスナップショット のタイムスタンプをatClusterTimeとして選択し、それをクライアントに返します。

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

  • に許可される値は、atClusterTime minSnapshotHistoryWindowInSecondsパラメータによって異なります。minSnapshotHistoryWindowInSeconds は、 ストレージエンジンがスナップショット履歴を保持する最小時間ウィンドウを秒単位で示します。 によって保持された最も古いスナップショットよりも古い atClusterTime 値を指定すると、minSnapshotHistoryWindowInSeconds mongodはエラーを返します。

  • "snapshot"atClusterTime遅延レプリカセットノードに対して を指定せずに で読み取り操作を実行すると、返される過半数のコミット済みデータが古い可能性があります。atClusterTime を指定すると、mongod は古いデータを返す代わりに指定されたタイムスタンプだけ待機しますが、読み取りのブロックやタイムアウトが発生する可能性があります。

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

MongoDB8.0 以降では、Capped"snapshot" コレクションで読み取り保証 (read concern) を使用できます。