sh.balancerCollectionStatus()
定义
sh.balancerCollectionStatus(namespace)
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.
重要
mongosh 方法
本页面提供
mongosh
方法的相关信息。这不是数据库命令或特定语言驱动程序(例如 Node.js)的相关文档。有关数据库命令,请参阅
balancerCollectionStatus
命令。如需了解 MongoDB API 驱动程序,请参阅特定语言的 MongoDB 驱动程序文档。
兼容性
This method is available in deployments hosted in the following environments:
MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
重要
This command is not supported in M0, M2, and M5 clusters. For more information, see Unsupported Commands.
MongoDB Enterprise:基于订阅、自我管理的 MongoDB 版本
MongoDB Community:源代码可用、免费使用且可自行管理的 MongoDB 版本
Syntax
The sh.balancerCollectionStatus()
has the following form:
sh.balancerCollectionStatus( <namespace> )
Parameter
The sh.balancerCollectionStatus()
method takes the following parameter:
Access Control
When running with access control, the user must have the
enableSharding
privilege actions on database
and/or collection to run the
method. 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.
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:
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:
{ "chunkSize": Long("128"), "balancerCompliant": false, "firstComplianceViolation": "defragmentingChunks", "details": { "currentPhase": "moveAndMergeChunks", "progress": { "remainingChunksToProcess": 1 } } }
注意
Chunk defragmentation occurs in multiple phases. The progress
field
only pertains to the current phase.
For the description of the output, see balancerCollectionStatus Output.