Definition定义
checkMetadataConsistencyPerforms a series of consistency checks on sharding metadata for a cluster, database, or collection. The command returns a cursor with either all or a batch of the inconsistency results found.对集群、数据库或集合的分片元数据执行一系列一致性检查。该命令返回一个游标,其中包含所有或一批发现的不一致结果。Tip
In在mongosh, this command can also be run through thedb.checkMetadataConsistency(),db.collection.checkMetadataConsistency(), orsh.checkMetadataConsistency()helper methods.mongosh中,此命令也可以通过db.checkMetadataConsistency()、db.collection.checkMetadataConsistency()或sh.checkMetadataConsistency()辅助方法运行。Helper methods are convenient for助手方法对mongoshusers, but they may not return the same level of information as database commands. In cases where the convenience is not needed or the additional return fields are required, use the database command.mongosh用户来说很方便,但它们可能不会返回与数据库命令相同级别的信息。如果不需要便利性或需要额外的返回字段,请使用database命令。Run this command after major maintenance operations, such as upgrades and downgrades, to check the state of the catalog.在主要维护操作(如升级和降级)后运行此命令,以检查目录的状态。By default, the command does not check indexes for consistency across the shards. To check indexes, set the默认情况下,该命令不会检查分片之间的索引一致性。要检查索引,请设置checkIndexesoption.checkIndexes选项。New in version 7.0.在版本7.0中新增。
Compatibility兼容性
This command is available in deployments hosted in the following environments:此命令在以下环境中托管的部署中可用:
- MongoDB Atlas
: The fully managed service for MongoDB deployments in the cloud:云中MongoDB部署的完全托管服务
Note
This command is supported in all MongoDB Atlas clusters. 所有MongoDB Atlas集群都支持此命令。For information on Atlas support for all commands, see Unsupported Commands.有关Atlas支持所有命令的信息,请参阅不支持的命令。
- MongoDB Enterprise
: The subscription-based, self-managed version of MongoDB:MongoDB的基于订阅的自我管理版本 - MongoDB Community
: The source-available, free-to-use, and self-managed version of MongoDB:MongoDB的源代码可用、免费使用和自我管理版本
Note
The checkMetadataConsistency command is executable only when connecting to mongos. mongod does not support this command.checkMetadataConsistency命令仅在连接到mongos时可执行。mongod不支持此命令。
Syntax语法
To check the entire cluster for sharding metadata inconsistencies, run the command from the要检查整个集群是否存在分片元数据不一致,请从admindatabase.admin数据库运行该命令。db.adminCommand( {
checkMetadataConsistency: 1
} )To check the database for sharding metadata inconsistencies, run the command from the database context:要检查数据库是否存在分片元数据不一致,请从数据库上下文运行以下命令:use cars
db.runCommand( {
checkMetadataConsistency: 1
} )To check a collection for sharding metadata inconsistencies, run the command with the collection name:要检查集合是否存在分片元数据不一致,请使用集合名称运行命令:use library
db.runCommand( {
checkMetadataConsistency: "authors",
} )
Command Fields命令字段
checkMetadataConsistency |
| |
checkIndexes |
| |
cursor | ||
cursor.batchSize | ||
dbMetadataLockMaxTimeMS |
|
Output输出
The checkMetadataConsistency command returns a cursor with a document for each inconsistency found in sharding metadata. To learn more, see Inconsistency Types.checkMetadataConsistency命令为分片元数据中发现的每个不一致返回一个带有文档的游标。要了解更多信息,请参阅不一致类型。
The return document has the following fields:
cursor | ||
cursor.id |
| |
cursor.ns | ||
cursor.firstBatch | ||
ok |
Behavior行为
Batch Results批量结果
The checkMetadataConsistency command returns results in batches. To customize the batch size, the batchSize option:checkMetadataConsistency命令分批返回结果。要自定义批大小,请使用batchSize选项:
var cur = db.runCommand( {
checkMetadataConsistency: 1,
cursor: {
batchSize: 10
}
} )
If the 如果cursor.id field is greater than 0, you can use with the getMore command to retrieve the next batch of results.cursor.id字段大于0,则可以使用getMore命令检索下一批结果。
Check Indexes检查索引
The 默认情况下,checkMetadataConsistency command does not check indexes by default. To check metadata consistency and indexes, use the checkIndexes option:checkMetadataConsistency命令不检查索引。要检查元数据一致性和索引,请使用checkIndexes选项:
db.runCommand( {
checkMetadataConsistency: 1,
checkIndexes: true
} )Example示例
Use 使用runCommand() to run the checkMetadataConsistency command:runCommand()运行checkMetadataConsistency命令:
db.runCommand( { checkMetadataConsistency: 1 } )
Example Output:输出示例:
{
cursor: {
id: Long("0"),
ns: "test.$cmd.aggregate",
firstBatch: [
{
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")
}
}
],
},
ok: 1
}