Why doesn't indexSize go down when removing documents?

Hi, we have a collection with about 500 million documents. While doing some preparation to shard the collection, we noticed something unexpected in our test environment. When deleting documents the size of various indexes doesn’t go down. We retrieve the index sizes by running db.collection.stats().indexSizes.

Is there expected behavior? Is there a way to compact the indexes? Does mongo not give back the index, but rather re-use it?

Hi Amit,

I’m sorry I don’t have an answer but I have the exact same question too. This isn’t, unfortunately, a widely talked about topic either in documentation or on other forums.

If you have found a reasonable explanation for this, please do share here.

Thanks,
Murali