db.collection.getShardDistribution()

Definition

  • db.collection.getShardDistribution()

mongo Shell Method

This page documents the mongo shell method, and doesnot refer to the MongoDB Node.js driver (or any other driver)method. For corresponding MongoDB driver API, refer to your specificMongoDB driver documentation instead.

Prints the data distribution statistics for a sharded collection.

Tip

Before running the method, use the flushRouterConfigcommand to refresh the cached routing table to avoid returningstale distribution information for the collection. Oncerefreshed, run db.collection.getShardDistribution() forthe collection you wish to build the index.

For example:

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

See also

Sharding

Output

Sample Output

The following is a sample output for the distribution of a shardedcollection:

  1. Shard shard-a at shard-a/MyMachine.local:30000,MyMachine.local:30001,MyMachine.local:30002
  2. data : 38.14Mb docs : 1000003 chunks : 2
  3. estimated data per chunk : 19.07Mb
  4. estimated docs per chunk : 500001
  5.  
  6. Shard shard-b at shard-b/MyMachine.local:30100,MyMachine.local:30101,MyMachine.local:30102
  7. data : 38.14Mb docs : 999999 chunks : 3
  8. estimated data per chunk : 12.71Mb
  9. estimated docs per chunk : 333333
  10.  
  11. Totals
  12. data : 76.29Mb docs : 2000002 chunks : 5
  13. Shard shard-a contains 50% data, 50% docs in cluster, avg obj size on shard : 40b
  14. Shard shard-b contains 49.99% data, 49.99% docs in cluster, avg obj size on shard : 40b

Output Fields

  1. Shard <shard-a> at <host-a>
  2. data : <size-a> docs : <count-a> chunks : <number of chunks-a>
  3. estimated data per chunk : <size-a>/<number of chunks-a>
  4. estimated docs per chunk : <count-a>/<number of chunks-a>
  5.  
  6. Shard <shard-b> at <host-b>
  7. data : <size-b> docs : <count-b> chunks : <number of chunks-b>
  8. estimated data per chunk : <size-b>/<number of chunks-b>
  9. estimated docs per chunk : <count-b>/<number of chunks-b>
  10.  
  11. Totals
  12. data : <stats.size> docs : <stats.count> chunks : <calc total chunks>
  13. Shard <shard-a> contains <estDataPercent-a>% data, <estDocPercent-a>% docs in cluster, avg obj size on shard : stats.shards[ <shard-a> ].avgObjSize
  14. 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).

  • <count-x> is a number that reports the number ofdocuments in the shard.

  • <number of chunks-x> is a number that reports thenumber of chunks in the shard.

  • <size-x>/<number of chunks-x> is a calculated valuethat reflects the estimated data size per chunk for the shard,including the unit of measure (e.g. b, Mb).

  • <count-x>/<number of chunks-x> is a calculated valuethat reflects the estimated number of documents per chunk for theshard.

  • <stats.size> is a value that reports the total size ofthe data in the sharded collection, including the unit of measure.

  • <stats.count> is a value that reports the total numberof documents in the sharded collection.

  • <calc total chunks> is a calculated number that reports thenumber of chunks from all shards, for example:

  1. <calc total chunks> = <number of chunks-a> + <number of chunks-b>
  • <estDataPercent-x> is a calculated value thatreflects, for each shard, the data size as the percentage of thecollection’s total data size, for example:
  1. <estDataPercent-x> = <size-x>/<stats.size>
  • <estDocPercent-x> is a calculated value thatreflects, for each shard, the number of documents as thepercentage of the total number of documents for the collection,for example:
  1. <estDocPercent-x> = <count-x>/<stats.count>
  • stats.shards[ <shard-x> ].avgObjSize is a number thatreflects the average object size, including the unit of measure,for the shard.