How can I run getShardDistribution() using pymongo

Hi Vaseem

From pymongo you can call the aggregation stage $shardedDataDistribution in order to retrieve the shard distribution of sharded collections.

Here an example

import pymongo
client = pymongo.MongoClient()
pipeline = [{"$shardedDataDistribution":{}}]
c=client["admin"].aggregate(pipeline)
print(c.next())
{'ns': 'myDB.mycoll 'shards': [{'shardName': 'shard01', 'numOrphanedDocs': 0, 'numOwnedDocuments': 0, 'ownedSizeBytes': 0, 'orphanedSizeBytes': 0}]}