"snapshot"
On this page本页内容
New in version 4.0.在版本4.0中新增。
Changed in version 5.0.在版本5.0中更改。
Read concern "snapshot"
is available for multi-document transactions, and starting in MongoDB 5.0, certain read operations outside of multi-document transactions.
"majority"
, the transaction operations are guaranteed to have read from a snapshot of majority-committed data."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 Operations That Support Read Concern.有关接受读关注的所有操作的列表,请参阅支持读关注的操作。
Multi-document transactions support read concern "snapshot"
as well as "local"
, and "majority"
.
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.要设置事务的读取关注点,请参阅事务和读取关注点。
atClusterTime
New in version 5.0.在版本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)
."snapshot"
执行查找操作,并指定该操作应在群集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."snapshot"
读取保证从大多数提交的数据中读取。
atClusterTime
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."snapshot"
against a delayed replica set member, the returned majority-committed data could be stale."snapshot"
的读取操作,则返回的多数提交数据可能已过时。atClusterTime
for "snapshot"
inside of causally consistent sessions.Starting in version 5.0, you cannot use read concern 从版本5.0开始,在读取封顶集合时,不能使用读取关注点"snapshot"
when reading from a capped collection."snapshot"
。