I'm trying to manage disk space usage for my mongodb using WiredTiger.
So far I have understood that when you delete documents from mongodb, WiredTiger doesn't give the acquired free space back to the OS but rather saves it for itself.
Now, I'm trying to make use of the metrics of db.Stats() that mongodb provides (https://www.mongodb.com/docs/manual/reference/command/dbStats/)
I'm especially interested in the 'free_' metrics to calculate how much space is left on the disk provided by the OS to mongodb.
After several hours of testing to understand the changes in metrics which didn't make any sense to me regarding the operations I did on the mongodb, I was thinking and testing the following mechanism for which I'm still in search of a confirmation as the mongodb docs seem to be not very precise at this point:
If documents are deleted from collection A, WiredTiger saves the acquired space for itself and the 'freeStorage' metrics from db.Stats() increase. But mongodb, or WiredTiger rather, is reusing the amount of space available in the 'freeStorage' metrics ONLY if you insert new documents in the same collection A. Is this assumption correct?
It is not that it would re-use the space if you create new documents in collection B, right? In this case it would consume new OS disk space which increases the fsUsedSize.
Can you confirm this and is there any official docs that points that out?
Asked by TheDude
(101 rep)
Apr 18, 2025, 11:51 AM