Starting in MongoDB 4.4 for sharded clusters, you can specify the use of hedged reads for non-从MongoDB 4.4开始,对于分片集群,您可以为非primary
read preferences.primary
读取首选项指定使用对冲读取。
With hedged reads, the 使用对冲读取,mongos
instances can route read operations to two replica set members per each queried shard and return results from the first respondent per shard.mongos
实例可以将读取操作路由到每个查询分片的两个副本集成员,并返回每个分片的第一个响应者的结果。
Hedged reads are supported for the following operations:以下操作支持对冲读取:
To specify hedged read for a read preference, MongoDB 4.4 introduces the hedged read option for read preferences.为了指定读取首选项的对冲读取,MongoDB 4.4为读取首选项引入了对冲读取选项。
To use hedged reads, enable the hedge read option for non-要使用对冲读取,请为非primary
read preferences. primary
读取首选项启用对冲读取选项。Read preference 读取首选项nearest
specifies hedged read by default.nearest
指定默认情况下的对冲读取。
mongosh
, you can use the helper methods cursor.readPref()
and Mongo.setReadPref()
.mongosh
时,可以使用助手方法cursor.readPref()
和Mongo.setReadPref()
。For more information on hedged reads, see Hedged Reads.有关套期读取的更多信息,请参阅对冲读取。
For details on member selection for hedged reads, see Read Preference and Shards.有关对冲读取的成员选择的详细信息,请参阅读取偏好和分片。
The command 命令serverStatus
and its corresponding mongosh
method db.serverStatus()
return hedgingMetrics
.serverStatus
及其对应的mongosh
方法db.serverStatus()
返回hedgingMetrics
。