db.collection.getShardDistribution()

On this page本页内容

Definition定义

db.collection.getShardDistribution()

mongo Shell Method

This page documents the mongo shell method, and does not refer to the MongoDB Node.js driver (or any other driver) method. 本页记录了mongo shell方法,未提及MongoDB Node.js驱动程序(或任何其他驱动程序)方法。For corresponding MongoDB driver API, refer to your specific MongoDB driver documentation instead.有关相应的MongoDB驱动程序API,请参阅特定的MongoDB驱动程序文档。

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();

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.是反映碎片的平均对象大小(包括度量单位)的数字。