Docs Home → Develop Applications → MongoDB Manual
balancerCollectionStatus
On this page
Definition
balancerCollectionStatus
New in version 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.
You can only issue the
balancerCollectionStatus
against theadmin
database.The command takes the following form:
db.adminCommand( { balancerCollectionStatus: "<db>.<collection>" } ) Specify the full namespace ("<db>.<collection>") of the sharded collection.
mongosh
provides a wrapper methodsh.balancerCollectionStatus()
.
Access Control
When running with access control, the user must have the
enableSharding
privilege actions on database
and/or collection to run the
command. 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.
Output Document
The following is an example of a document returned by the command:
{ "balancerCompliant" : false, "firstComplianceViolation" : "chunksImbalance", "ok" : 1, "operationTime" : Timestamp(1583192967, 16), "$clusterTime" : { "clusterTime" : Timestamp(1583192967, 16), "signature" : { "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="), "keyId" : NumberLong(0) } } }
Field | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|
"balancerCompliant" | A boolean that indicates whether the chunks do not need to be
moved ( true ) or need to be moved (false ). | ||||||||
"firstComplianceViolation" | A string that indicates the reason chunks for this namespace need to be
moved. The field is only available if Possible values are:
|
In addition to the command-specific return fields, the command also
returns the ok
status field, the operationTime
field, and the
$clusterTime
field for the operation. For details on these fields,
see Response.
Example
To check whether the chunks of a sharded collection test.contacts
is currently in balance, connect to a mongos
instance
and issue the following command:
db.adminCommand( { balancerCollectionStatus: "test.contacts" } )
If the chunks for the collection do not need to be moved, the command 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) } } }