db.collection.checkMetadataConsistency()
定义
db.collection.checkMetadataConsistency(options)
Performs a series of consistency checks on sharding metadata for the collection. The method returns a cursor with either all or a batch of the inconsistency results found.
重要
mongosh 方法
本页面提供
mongosh
方法的相关信息。这不是数据库命令或特定语言驱动程序(例如 Node.js)的相关文档。有关数据库命令,请参阅
checkMetadataConsistency
命令。如需了解 MongoDB API 驱动程序,请参阅特定语言的 MongoDB 驱动程序文档。
Run this method after major maintenance operations, such as upgrades and downgrades, to check the state of the catalog.
默认,该方法不会检查索引在分片之间的一致性。 如果索引检查与创建、删除或修改索引的操作同时运行,则可能会返回不一致的误报。 要使用此方法检查索引,请设立
checkIndexes
选项。有关此方法检查不一致的更多信息,请参阅不一致类型。
返回: 此方法返回带有 documents
数组的游标,该数组包含分片元数据中发现的每个不一致的文档。
兼容性
此方法可用于以下环境中托管的部署:
MongoDB Atlas:用于云中 MongoDB 部署的完全托管服务
重要
M0、M2、M5 和 Flex 集群不支持此命令。有关更多信息,请参阅不支持的命令。
MongoDB Enterprise:基于订阅、自我管理的 MongoDB 版本
MongoDB Community:源代码可用、免费使用且可自行管理的 MongoDB 版本
注意
checkMetadataConsistency
助手仅在连接到 mongos
时才可执行。 mongod
不支持此方法。
语法
db.collection.checkMetadataConsistency()
方法使用的语法如下:
db.collection.checkMetadataConsistency( { <options> } )
options
文档可以采用以下字段和值:
字段 | 类型 | 说明 |
---|---|---|
| 布尔 | 设置该命令是否还检查分片元数据中的索引。 默认情况下,此操作处于禁用状态,因为与创建、删除或修改索引的操作并发运行时,它可能会返回不一致的误报。 仅当您知道这些操作不太可能发生时才检查索引。 |
| 文档 | 配置返回游标。 |
| 整型 | 每个批次中包含的分片元数据不一致文档的最大数量。 |
例子
db.authors.checkMetadataConsistency()
{ cursorHasMore: false, documents: [ { type: "MisplacedCollection", description: "Unsharded collection found on shard different from database primary shard", details: { namespace: "test.authors", shard: "shard02", localUUID: new UUID("1ad56770-61e2-48e9-83c6-8ecefe73cfc4") } } ], }