Docs HomeMongoDB Manual

$shardedDataDistribution (aggregation)

Definition

$shardedDataDistribution

New in version 6.0.3.

Returns information on the distribution of data in sharded collections.

Note

This aggregation stage is only available on mongos.

This aggregation stage must be run on the admin database. The user must have the shardedDataDistribution privilege action.

Syntax

The shardedDataDistribution stage has the following syntax:

db.aggregate( [
   { $shardedDataDistribution: { } }
] )

Output Fields

The $shardedDataDistribution stage outputs an array of documents for each sharded collection in the database. These documents contain the following fields:

Field NameData TypeDescription
nsstringThe namespace of the sharded collection.
shardsarrayLists the shards in the collection with data distribution information on each shard.
shards.numOrphanedDocsintegerNumber of orphaned documents in the shard.
shards.numOwnedDocumentsintegerNumber of documents owned by the shard.
shards.orphanedSizeBytesintegerAmount of storage in bytes used by orphaned documents in the shard.
shards.ownedSizeBytesintegerAmount of storage in bytes used by owned documents in the shard.

Examples

db.aggregate( [
   { $shardedDataDistribution: { } }
] )

Example output:

[
  {
    "ns": "test.names",
    "shards": [
      {
        "shardName": "shard-1",
        "numOrphanedDocs": 0,
        "numOwnedDocuments": 6,
        "ownedSizeBytes": 366,
        "orphanedSizeBytes": 0
      },
      {
        "shardName": "shard-2",
        "numOrphanedDocs": 0,
        "numOwnedDocuments": 6,
        "ownedSizeBytes": 366,
        "orphanedSizeBytes": 0
      }
    ]
  }
]