Docs HomeMongoDB Manual

db.collection.getShardDistribution()

On this page本页内容

Definition定义

db.collection.getShardDistribution()
Important

mongosh Method

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

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

Prints the data distribution statistics for a sharded collection.打印分片集合的数据分布统计信息。

Tip

Before running the method, use the flushRouterConfig command to refresh the cached routing table to avoid returning stale distribution information for the collection. 在运行该方法之前,请使用flushRouterConfig命令刷新缓存的路由表,以避免返回集合的过时分发信息。Once refreshed, run db.collection.getShardDistribution() for the collection you wish to build the index.刷新后,对要构建索引的集合运行db.collection.getShardDistribution()

For example:例如:

db.adminCommand( { flushRouterConfig: "test.myShardedCollection" } );
db.getSiblingDB("test").myShardedCollection.getShardDistribution();
Tip

See also: 另请参阅:

Sharding分片

Output输出

Sample Output样本输出

The following is a sample output for the distribution of a sharded collection:以下是分片集合分布的示例输出:

Shard shard-a at shard-a/MyMachine.local:30000,MyMachine.local:30001,MyMachine.local:30002
data : 38.14Mb docs : 1000003 chunks : 2
estimated data per chunk : 19.07Mb
estimated docs per chunk : 500001

Shard shard-b at shard-b/MyMachine.local:30100,MyMachine.local:30101,MyMachine.local:30102
data : 38.14Mb docs : 999999 chunks : 3
estimated data per chunk : 12.71Mb
estimated docs per chunk : 333333

Totals
data : 76.29Mb docs : 2000002 chunks : 5
Shard shard-a contains 50% data, 50% docs in cluster, avg obj size on shard : 40b
Shard shard-b contains 49.99% data, 49.99% docs in cluster, avg obj size on shard : 40b

Output Fields输出字段

Shard <shard-a> at <host-a>
data : <size-a> docs : <count-a> chunks : <number of chunks-a>
estimated data per chunk : <size-a>/<number of chunks-a>
estimated docs per chunk : <count-a>/<number of chunks-a>

Shard <shard-b> at <host-b>
data : <size-b> docs : <count-b> chunks : <number of chunks-b>
estimated data per chunk : <size-b>/<number of chunks-b>
estimated docs per chunk : <count-b>/<number of chunks-b>

Totals
data : <stats.size> docs : <stats.count> chunks : <calc total chunks>
Shard <shard-a> contains <estDataPercent-a>% data, <estDocPercent-a>% docs in cluster, avg obj size on shard : stats.shards[ <shard-a> ].avgObjSize
Shard <shard-b> contains <estDataPercent-b>% data, <estDocPercent-b>% docs in cluster, avg obj size on shard : stats.shards[ <shard-b> ].avgObjSize

The output information displays:输出信息显示:

  • <shard-x> is a string that holds the shard name.是一个包含分片名称的字符串。
  • <host-x> is a string that holds the host name(s).是一个包含主机名的字符串。
  • <size-x> is a number that includes the size of the data, including the unit of measure (e.g. b, Mb).是一个包括数据大小的数字,包括度量单位(例如bMb)。
  • <count-x> is a number that reports the number of documents in the shard.是一个报告分片中文档数量的数字。
  • <number of chunks-x> is a number that reports the number of chunks in the shard.是一个报告分片中块的数量的数字。
  • <size-x>/<number of chunks-x> is a calculated value that reflects the estimated data size per chunk for the shard, including the unit of measure (e.g. b, Mb).是反映分片的每个块的估计数据大小的计算值,包括度量单位(例如,bMb)。
  • <count-x>/<number of chunks-x> is a calculated value that reflects the estimated number of documents per chunk for the shard.是一个计算值,反映了分片的每个区块的文档估计数量。
  • <stats.size> is a value that reports the total size of the data in the sharded collection, including the unit of measure.是一个值,用于报告分片集合中数据的总大小,包括度量单位。
  • <stats.count> is a value that reports the total number of documents in the sharded collection.是一个报告分片集合中文档总数的值。
  • <calc total chunks> is a calculated number that reports the number of chunks from all shards, for example:是报告来自所有分片的块的数目的计算的数目,例如:

    <calc total chunks> = <number of chunks-a> + <number of chunks-b>
  • <estDataPercent-x> is a calculated value that reflects, for each shard, the data size as the percentage of the collection's total data size, for example:是一个计算值,它反映了每个分片的数据大小占集合总数据大小的百分比,例如:

    <estDataPercent-x> = <size-x>/<stats.size>
  • <estDocPercent-x> is a calculated value that reflects, for each shard, the number of documents as the percentage of the total number of documents for the collection, for example:是一个计算值,它反映了每个分片的文档数占集合文档总数的百分比,例如:

    <estDocPercent-x> = <count-x>/<stats.count>
  • stats.shards[ <shard-x> ].avgObjSize is a number that reflects the average object size, including the unit of measure, for the shard.是一个反映分片的平均对象大小(包括度量单位)的数字。