How can I run getShardDistribution() using pymongo

Hi Team,

I’m new to mongodb and we are planning to use sharding feature in our company, so it became a priority for me to monitor it for shardDistribution, so i used pymongo example: db.collection_name.getShardDistribution() but it is not working, and I’m not sure what I’m missing
can someone help me with this?

Thanks
Vaseem

Hi @Vaseem_Akram_mohammad and welcome to the MongoDB community forum!!

The db.collection.getShardDistribution is a helper function which works only in the mongosh as of today.
The driver version of the command in pymongo are still not present in the latest release.

While there is no direct replacement of the command in Python, you may be able to get some part of the information by switching to the config database and perform some queries on the collections inside it. See Collections to Support Sharded Cluster Operations for more details on this.

However, please note that the contents of the config database are internal to MongoDB and may be subjected to change in future depending on the product requirement.

Let us know if you have any further queries.

Best Regards
Aasawari

2 Likes

Helo @Aasawari ,

Thank you

1 Like