cursor.readConcern()

On this page本页内容

Definition定义

cursor.readConcern(level)

mongo Shell Method

This page documents the mongo shell method, and does not refer to the MongoDB Node.js driver (or any other driver) method. 本页记录了mongo shell方法,未提及MongoDB Node.js驱动程序(或任何其他驱动程序)方法。For corresponding MongoDB driver API, refer to your specific MongoDB driver documentation instead.有关相应的MongoDB驱动程序API,请参阅特定的MongoDB驱动程序文档。

New in version 3.2.版本3.2中的新功能。

Specify a read concern for the db.collection.find() method.指定db.collection.find()方法的读取关注点

The readConcern() method has the following form:readConcern()方法的形式如下:

db.collection.find().readConcern(<level>)

The readConcern() method has the following parameter:readConcern()方法具有以下参数:

Parameter参数Type类型Description描述
level string

Read concern level.阅读关注级别。

Possible read concern levels are:可能的读取关注级别为:

For more formation on the read concern levels, see Read Concern Levels.有关阅读关注级别的更多信息,请参阅阅读关注级别

Considerations考虑事项

"majority" Read Concern阅读关注

To use read concern level of "majority", replica sets must use WiredTiger storage engine.要使用"majority"读关注级别,副本集必须使用WiredTiger存储引擎

You can disable read concern "majority" for a deployment with a three-member primary-secondary-arbiter (PSA) architecture; however, this has implications for change streams (in MongoDB 4.0 and earlier only) and transactions on sharded clusters. 对于具有三成员主从仲裁器(PSA)体系结构的部署,可以禁用读关注点"majority";然而,这对变更流(仅在MongoDB 4.0及更早版本中)和分片集群上的事务有影响。For more information, see Disable Read Concern Majority.有关更多信息,请参阅禁用读取关注多数

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 { w: "majority" } write concern, and then issue your read operation with primary read preference, and either "majority" or "linearizable" read concern.在MongoDB 3.6之前,为了读取您自己的写入操作,您必须使用{ w: "majority" }写入关注点来执行写入操作,然后使用主要读取首选项以及"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)

See also参阅

Read Concern阅读关注