Docs HomeMongoDB Manual

sh.balancerCollectionStatus()

Definition定义

sh.balancerCollectionStatus(namespace)

New in version 4.4. 4.4版新增。

Returns a document that contains information about whether the chunks of a sharded collection are balanced (i.e. do not need to be moved) as of the time the command is run or need to be moved because of draining shards, zone violation or imbalance of chunks across shards.返回一个文档,该文档包含关于在运行命令时,分片集合的块是否平衡(即不需要移动),或者由于耗尽分片、区域冲突或分片之间的块不平衡而需要移动的信息。

Important

mongosh Method

This page documents a mongosh method. This is not the documentation for database commands or language-specific drivers, such as Node.js.

For the database command, see the balancerCollectionStatus command.

For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.

For the legacy mongo shell documentation, refer to the documentation for the corresponding MongoDB Server release:

mongo shell v4.4

Syntax语法

The sh.balancerCollectionStatus() has the following form:sh.balancerCollectionStatus()具有以下形式:

sh.balancerCollectionStatus( <namespace> )

Parameter参数

The sh.balancerCollectionStatus() method takes the following parameter:sh.balancerCollectionStatus()方法采用以下参数:

Parameter参数Type类型Description描述
namespaceStringThe namespace of the collection to shard in the form "<database>.<collection>". 集合的命名空间以"<database>.<collection>"的形式分片。

Access Control访问控制

When running with access control, the user must have the enableSharding privilege actions on database and/or collection to run the method. 在使用访问控制运行时,用户必须对数据库和/或集合具有enableSharding权限操作才能运行该方法。That is, a user must have a role that grants the following privilege:也就是说,用户必须具有授予以下权限角色

{ resource: { db: <database>, collection: <collection> }, actions: [ "enableSharding" ] }

The built-in clusterManager role provides the appropriate privileges.内置的clusterManager角色提供适当的权限。

Examples实例

To check whether the chunks of a sharded collection test.contacts is currently in balance, connect to a mongos instance and issue the following:要检查分片集合test.contacts的块当前是否处于平衡状态,请连接到mongos实例并发出以下消息:

sh.balancerCollectionStatus("test.contacts")

If the chunks for the collection do not need to be moved, the method returns an output similar to the following:如果不需要移动集合的块,该方法将返回类似于以下内容的输出:

{
"balancerCompliant" : true,
"ok" : 1,
"operationTime" : Timestamp(1583193238, 1),
"$clusterTime" : {
"clusterTime" : Timestamp(1583193238, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}

Ongoing Defragmentation Process正在进行的分片整理过程

If the queried namespace is going through chunk defragmentation, the sh.balancerCollectionStatus method returns output similar to the following:如果查询的命名空间正在进行区块分片整理,sh.balancerCollectionStatus方法将返回类似于以下内容的输出:

{
"chunkSize": Long("128"),
"balancerCompliant": false,
"firstComplianceViolation": "defragmentingChunks",
"details": {
"currentPhase": "moveAndMergeChunks",
"progress": { "remainingChunksToProcess": 1 }
}
}
Note

Chunk defragmentation occurs in multiple phases. The progress field only pertains to the current phase.区块分片整理分为多个阶段。progress字段仅适用于当前阶段。

For the description of the output, see balancerCollectionStatus Output.有关输出的描述,请参阅balancerCollectionStatus输出