sh.balancerCollectionStatus()

On this page本页内容

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.返回一个文档,其中包含有关在运行命令时分片集合的块是否平衡(即不需要移动)的信息,或者由于分片之间的分片排出、区域冲突或块不平衡而需要移动的信息。

The mongosh method sh.balancerCollectionStatus() wraps the balancerCollectionStatus command.mongosh方法sh.balancerCollectionStatus()包装了balancerCollectionStatus命令。

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描述
namespaceString

The 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角色提供适当的权限。

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:要检查分片集合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)
      }
   }
}

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

←  sh.addTagRange()sh.commitReshardCollection() →