On this page本页内容
db.collection.getShardDistribution()
This is a mongosh
method. This is not the documentation for Node.js
or other programming language specific driver methods.
In most cases, mongosh
methods work the same way as the legacy mongo
shell methods. However, some legacy methods are unavailable in mongosh
.
For the legacy mongo
shell documentation, refer to the documentation for the corresponding MongoDB Server release:
For MongoDB API drivers, refer to the language specific MongoDB driver documentation.
Prints the data distribution statistics for a sharded collection.打印分片集合的数据分布统计信息。
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();
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
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>
<host-x>
<size-x>
b
, Mb
).b
、Mb
)。<count-x>
<number of chunks-x>
<size-x>/<number of chunks-x>
b
, Mb
).b
、Mb
)。<count-x>/<number of chunks-x>
<stats.size>
<stats.count>
<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