(mongodb >=1.1.0)
MongoDB\Driver\ReadConcern controls the level of isolation for read operations for replica sets and replica set shards. This option requires MongoDB 3.2 or later.
MongoDB\Driver\ReadConcern::AVAILABLE
Default for reads against secondaries when afterClusterTimeand level are unspecified.
The query returns the instance's most recent data. Provides no guarantee that the data has been written to a majority of the replica set members (i.e. may be rolled back).
For unsharded collections (including collections in a standalone deployment or a replica set deployment), "local" and "available" read concerns behave identically.
For a sharded cluster, "available" read concern provides greater tolerance for partitions since it does not wait to ensure consistency guarantees. However, a query with "available" read concern may return orphan documents if the shard is undergoing chunk migrations since the "available" read concern, unlike "local" read concern, does not contact the shard's primary nor the config servers for updated metadata.
MongoDB\Driver\ReadConcern::LINEARIZABLE
The query returns data that reflects all successful writes issued with a
write concern of "majority" and
acknowledged prior to the start of the read operation. For replica sets
that run with writeConcernMajorityJournalDefault set
to TRUE
, linearizable read concern returns data that will never be
rolled back.
With writeConcernMajorityJournalDefault set to
FALSE
, MongoDB will not wait for w: "majority"
writes to be durable before acknowledging the writes. As such,
"majority" write operations could possibly roll back
in the event of a loss of a replica set member.
You can specify linearizable read concern for read operations on the primary only.
Linearizable read concern guarantees only apply if read operations specify a query filter that uniquely identifies a single document.
Always use maxTimeMS with linearizable read concern in case a majority of data bearing members are unavailable. maxTimeMS ensures that the operation does not block indefinitely and instead ensures that the operation returns an error if the read concern cannot be fulfilled.
Linearizable read concern requires MongoDB 3.4.
MongoDB\Driver\ReadConcern::LOCAL
Default for reads against primary if level is unspecified and for reads against secondaries if level is unspecified but afterClusterTime is specified.
The query returns the instance's most recent data. Provides no guarantee that the data has been written to a majority of the replica set members (i.e. may be rolled back).
MongoDB\Driver\ReadConcern::MAJORITY
The query returns the instance's most recent data acknowledged as having been written to a majority of members in the replica set.
To use read concern level of "majority", replica sets must use WiredTiger storage engine and election protocol version 1.
版本 | 说明 |
---|---|
1.7.0 | Implements Serializable. |
1.4.0 |
Added the |
1.2.0 |
Added the
Implements MongoDB\BSON\Serializable. |