cursor.readConcern()
On this page本页内容
Definition定义
cursor.readConcern(level)
- Important
mongosh Method
This page documents a
mongosh
method. This is not the documentation for a language-specific driver, such as Node.js.For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.
Specify a read concern for the为db.collection.find()
method.db.collection.find()
方法指定一个读取关注。ThereadConcern()
method has the following form:readConcern()
方法的形式如下:db.collection.find().readConcern(<level>)
ThereadConcern()
method has the following parameter:readConcern()
方法具有以下参数:Parameter参数Type类型Description描述level
string Read concern读取关注level.级别。
Possible read concern levels are:可能的读取关注级别为:"local"
.This is the default read concern level for read operations against the primary and secondaries.这是针对主和辅助的读取操作的默认读取关注级别。"available"
.Available for read operations against the primary and secondaries.可用于对primary和secondary进行读取操作。对于主和非分片的辅助,"available"
behaves the same as"local"
against the primary and non-sharded secondaries."available"
的行为与"local"
相同。The query returns the instance's most recent data.查询返回实例的最新数据。"majority"
.Available for replica sets that use WiredTiger storage engine.适用于使用WiredTiger存储引擎的复制副本集。"linearizable"
.Available for read operations on the仅可用于primary
only.primary
上的读取操作。
For more formation on the read concern levels, see Read Concern Levels.有关读取关注级别的更多信息,请参阅读取关注级别。
Considerations注意事项
Read Your Own Writes阅读自己的文章
Starting in MongoDB 3.6, you can use causally consistent sessions to read your own writes, if the writes request acknowledgement.从MongoDB 3.6开始,如果写入请求确认,您可以使用因果一致会话来读取自己的写入。
Prior to MongoDB 3.6, in order to read your own writes you must issue your write operation with 在MongoDB 3.6之前,为了读取您自己的写入,您必须发出具有{ w: "majority" }
write concern, and then issue your read operation with primary
read preference, and either "majority"
or "linearizable"
read concern.{ w: "majority" }
写入关注的写入操作,然后发出具有primary
读取偏好的读取操作,以及"majority"
或"linearizable"
读取关注。
Linearizable Read Concern Performance可线性化的读取关注性能
When specifying 在指定可线性化的读取关注时,如果大多数数据承载成员不可用,请始终使用linearizable read concern
, always use maxTimeMS()
in case a majority of data bearing members are unavailable.maxTimeMS()
。
db.restaurants.find( { _id: 5 } ).readConcern("linearizable").maxTimeMS(10000)