sh.getShardedDataDistribution()
On this page
Definition
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.
Compatibility
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.
MongoDB Enterprise: The subscription-based, self-managed version of MongoDB
MongoDB Community: The source-available, free-to-use, and self-managed version of MongoDB
Syntax
The method has the following syntax:
sh.getShardedDataDistribution()
Example
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. |