'Get index size on each shard?

I have a compound index on a sharded cluster living on Mongo Atlas. The Atlas UI tells me the index size is 10.1GB. Similarly,

MongoDB Enterprise > db.myCollection.stats().indexSizes
{
    "_id_" : 14387392512,
    "my_index" : 10810015744
}

My cluster has two shards. Can I assume that there is actually 5GB of index on each shard, since each shard contains its own indexing? Is there a way to get the exact size of the index on each shard? If I add a third shard, will this index size be reduced to ~3.3GB per shard, assuming a balanced distribution?

I want to ensure that my index size + working set remains in RAM and find the right balance of vertical scaling (upgrading cluster tiers) vs. horizontal scaling (adding more shards) to accommodate this.



Solution 1:[1]

You are on correct path. Once collection is sharded the db.stats() will give stats of entire database and each shard documents/size/indexe size/total size and other things. We have created a report based on this to show daily shard distribution. This in python gives dictionary and easy to get values

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mahesh Malpani