On this page本页内容
Retryable reads allow MongoDB drivers to automatically retry certain read operations a single time if they encounter certain network or server errors.可重试读取允许MongoDB驱动程序在遇到某些网络或服务器错误时自动重试某些读取操作。
Official MongoDB drivers compatible with MongoDB Server 4.2 and later support retryable reads.与MongoDB Server 4.2及更高版本兼容的官方MongoDB驱动程序支持可重试读取。
For more information on official MongoDB drivers, see MongoDB Drivers.有关官方MongoDB驱动程序的更多信息,请参阅MongoDB驱动程序。
Official MongoDB drivers compatible with MongoDB Server 4.2 and later enable retryable reads by default. 与MongoDB Server 4.2及更高版本兼容的官方MongoDB驱动程序默认启用可重试读取。To explicitly disable retryable reads, specify 要显式禁用可重试读取,请在部署的连接字符串中指定retryReads=false
in the connection string for the deployment.retryReads=false
。
mongosh
does not support retryable reads.mongosh
不支持可重试读取。
MongoDB drivers support retrying the following read operations. MongoDB驱动程序支持重试以下读取操作。The list references a generic description of each method. 该列表引用了每种方法的通用描述。For specific syntax and usage, defer to the driver documentation for that method.对于特定的语法和用法,请遵循该方法的驱动程序文档。
Collection.aggregate Collection.count Collection.countDocuments Collection.distinct Collection.estimatedDocumentCount Collection.find Database.aggregate
| |
Collection.watch Database.watch MongoClient.watch | |
MongoClient.listDatabases Database.listCollections Collection.listIndexes | |
Collection.find (e.g. GridFSBucket.openDownloadStream )Collection.find 支持的GridFS操作(例如GridFSBucket.openDownloadStream ) |
MongoDB drivers may include retryable support for other operations, such as helper methods or methods that wrap a retryable read operation. MongoDB驱动程序可能包括对其他操作的可重试支持,例如帮助器方法或包装可重试读取操作的方法。Defer to the driver documentation to determine whether a method explicitly supports retryable reads.根据驱动程序文档确定方法是否显式支持可重试读取。
Retryable Read Specification: 可检索读取规范:Supported Read Operations支持的读取操作
The following operations do not support retryable reads:以下操作不支持可重试读取:
db.collection.mapReduce()
getMore
Database.runCommand
helper, which is agnostic about read or write commands.Database.runCommand
助手的读取命令,该助手对读取或写入命令不可知。MongoDB retryable reads make only one retry attempt. MongoDB可重试读取只进行一次重试尝试。This helps address transient network errors or replica set elections, but not persistent network errors.这有助于解决暂时性网络错误或副本集选择,但不能解决持久性网络错误。
The driver performs server selection using the read command's original read preference before retrying the read operation. 在重试读取操作之前,驱动程序使用读取命令的原始读取首选项执行服务器选择。If the driver cannot select a server for the retry attempt using the original read preference, the driver returns the original error.如果驱动程序无法使用原始读取首选项为重试尝试选择服务器,则驱动程序将返回原始错误。
The drivers wait 驱动程序在执行服务器选择之前等待serverSelectionTimeoutMS
milliseconds before performing server selection. serverSelectionTimeoutMS
毫秒。Retryable reads do not address instances where no eligible servers exist after waiting 可重试读取不会处理等待serverSelectionTimeoutMS
.serverSelectionTimeoutMS
后不存在符合条件的服务器的实例。