Docs Menu

Docs HomeDevelop ApplicationsMongoDB Manual

sh.getShardedDataDistribution()

On this page

  • Definition
  • 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.

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
Storage in bytes for documents owned by the shard.
shards.orphanedSizeBytes
integer
Storage in bytes for orphaned documents in the shard.
← sh.getBalancerState()