Sharding increases count and size of collection, what to do?

Hi, I have 3 shards with having 2 replica sets(P+S+S) and one mongos and when i am going to perform sharding on one collection of size 5.6GB and after sharding we observed size and document count started increasing
suppose we have 1000 doc in shard 1 then after sharding when we connect to mongo shell count of doc showing 1500 and we found size is also consumed more than previous one
Do we have any solution for that?

The increased document count that you observe after sharding a collection is related to chunk balancing and orphaned dociments.

As your sharded cluster starts to balance chunks, documents will be moved between shards, for example, from shard 0 to shard 1.

A copy of documents from shard 0 will be moved over to shard 1, and the original documents on shard 0 will be marked for deletion, also known as orphaned documents.

Depending on your cluster tier, and how busy it is, these orphaned documents will be removed in the future. Sometimes this can happen around 24 hours after the chunk migration.

You can read more about orphaned documents here:

Note that the orphaned document clean up is automated, so there’s no need to intervene.

If orphaned documents are having a negative effect on your cluster, you can try pausing the balancer, or setting a balancing window to throttle how many orphaned documents are being produced.

2 Likes