ANNOUNCEMENT: Voyage AI joins MongoDB to power more accurate and trustworthy AI applications on Atlas.
Learn more
Docs 菜单

db.checkMetadataConsistency()

db.checkMetadataConsistency(options)

Performs a series of consistency checks on sharding metadata for the cluster or database. This 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, or to check if the cluster metadata is inconsistent or corrupted due to bugs in previous releases of MongoDB.

By default, the method does not check indexes for consistency across the shards. Index checks can return false positive inconsistencies if they run concurrent with operations that create, delete, or modify indexes. To check indexes with this method, set the checkIndexes option.

By default, the method checks sharding metadata for the given database. If run on the admin database, it instead checks sharding metadata for the entire cluster.

For more information on the inconsistencies this method searches for, see 不一致类型.

返回:This method returns a cursor with a documents array, which contains a document for each inconsistency found in the sharding metadata.

此方法可用于以下环境中托管的部署:

重要

M0、M2、M5 和 Flex 集群不支持此命令。有关更多信息,请参阅不支持的命令。

注意

The checkMetadataConsistency helper is executable only when connecting to mongos. mongod does not support this method.

db.checkMetadataConsistency() 方法使用的语法如下:

db.checkMetadataConsistency( { <options> } )

The options document can take the following fields and values:

字段
类型
说明

checkIndexes

布尔

设置该命令是否还检查分片元数据中的索引。

By default, this operation is disabled, because if it can return false positives inconsistencies when run concurrent with operations that create, delete, or modify indexes. Only check indexes at times when you know these operations are unlikely to occur.

cursor

文档

配置返回游标。

cursor.batchSize

整型

Maximum number of sharding metadata inconsistency documents to include in each batch.

To perform consistency checks on a database, call the db.checkMetadataConsistency() method:

use library
db.checkMetadataConsistency()
{
cursorHasMore: false,
documents: [
{
type: "MisplacedCollection",
description: "Unsharded collection found on shard different from database primary shard",
details: {
namespace: "library.authors",
shard: "shard02",
localUUID: new UUID("1ad56770-61e2-48e9-83c6-8ecefe73cfc4")
}
}
],
}

To perform consistency checks on a cluster, call the db.checkMetadataConsistency() method from the admin database:

use admin
db.checkMetadataConsistency()
{
cursorHasMore: false,
documents: [
{
type: "MisplacedCollection",
description: "Unsharded collection found on shard different from database primary shard",
details: {
namespace: "library.authors",
shard: "shard02",
localUUID: new UUID("1ad56770-61e2-48e9-83c6-8ecefe73cfc4")
}
}
],
}