Extra space occupied by Indexes

Hi Community,

I recently removed several documents from a collection due to a business logic requirement. However, I noticed that instead of a reduction in index size, it has actually increased.

Given that the data size has decreased, I expected the index size to shrink as well, since the removed documents were the basis for those indexes.

Here are the details:

Index size before the removal process: 1.67 GB
Index size after the removal process: 2.71 GB

Note: These values were collected weekly, and the documents were removed at the end of the week. Even with this timeline, I expected a gradual reduction in index size compared to the previous week since approximately 5.2 million documents were deleted, leaving only 200,000 documents in the collection.

Any insights or suggestions on why this might be happening?

Size matters. But 1.1 gig should not. More importantly, did you see performance degradation?

In most cases, released memory is not returned to the OS because performance is better when memory reused within the application. In the case of MongoDB an update to a document involves writing back the whole document, in a unused block. If freed block are returned to the OS new blocks are then requested from the OS for new writes. This is inefficient.

Take a look at

May be it can help.

Answer to above question, no any changes in performance (Neither degraded nor improved).

If this is the scenario, then when should one return the memory to OS as if we won’t return it then there might be chance that it can lead to Memory Fragmentation Problem?

Yes I know about this command, but before implementing it I want to gather as much as information about Memory Fragmentation & how to fetch how much a memory is fragmentated, what would be the scenario when we need to return memory to OS? And all such questions.