Environment: MongoDB 4.2.7, Centos7
I have a collection with about 500 million document and an index that is about 8GB. If I delete half the documents, I would expect the indexSize to decrease by about 50%. But I don't. Why does it not go down? Is there a way to compact the index?
Just to verify that the index should be smaller, I copied 50% of the documents to a brand new mongodb instance and created the index there. The index is indeed about 50% less.
Well, I just found the answer to my own question. MongoDB actually has a compact command:
https://docs.mongodb.com/manual/reference/command/compact/
This should rebuild the indexes let me reclaim the free space.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With