Docs Menu
Docs Home
/
MongoDB Manual
/ / /

sh.getShardedDataDistribution()

On this page

  • Definition
  • Compatibility
  • Syntax
  • Example
  • Learn More
sh.getShardedDataDistribution()

New in version 6.0.3.

Returns data distribution information for sharded collections. sh.getShardedDataDistribution() is a shell helper method for the $shardedDataDistribution aggregation pipeline stage.

You can only run the method from a mongosh session connected to a mongos instance.

This method is available in deployments hosted in the following environments:

  • MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud

Important

This command is not supported in M0, M2, and M5 clusters. For more information, see Unsupported Commands.

The method has the following syntax:

sh.getShardedDataDistribution()

The following example runs the method:

sh.getShardedDataDistribution()

The method returns an array of documents for each sharded collection. For example:

[
{
ns: 'config.system.sessions',
shards: [
{
shardName: 'shard1',
numOrphanedDocs: 0,
numOwnedDocuments: 18,
ownedSizeBytes: 1782,
orphanedSizeBytes: 0
}
]
},
{
ns: 'records.people',
shards: [
{
shardName: 'shard1',
numOrphanedDocs: 0,
numOwnedDocuments: 21,
ownedSizeBytes: 134,
orphanedSizeBytes: 0
}
]
}
]

The following table describes the output fields:

Field Name
Data Type
Description
ns
string
Namespace of the sharded collection.
shards
array
Shards in the collection with the data distribution information for each shard.
shards.numOrphanedDocs
integer
Number of orphaned documents in the shard.
shards.numOwnedDocuments
integer
Number of documents owned by the shard.
shards.ownedSizeBytes
integer
Size in bytes of documents owned by the shard when uncompressed.
shards.orphanedSizeBytes
integer
Size in bytes of orphaned documents in the shard when uncompressed.

Back

sh.getBalancerState