Did you ever find a solution? - I have the exact same problem. When I run db.getMongo().setSecondaryOk(); - I am able to run compact on the Slave and it releases some space. However when I run db.runCommand({ compact: collectionName }); on the Master, it immediately returns and no space is released.
Hi @Roman_Gaufman1,
Moved to a new topic as there isn’t enough information to guarantee that the issue is the same. I will link this back to the original if this isn’t is the case.
In saying the above, can you provide the following information?:
- MongoDB version you tried this on
- Confirmation if
db.runCommand({ compact: collectionName });
was the command run on the node whilst it was stillPRIMARY
and if you used theforce
option - Note: as per thecompact
documentation for replica sets:
You should run
compact
on secondary nodes whenever possible.
- How much disk space are you expecting to be released? And to follow on, how are you calculating this? As per the Disk Space portion of the
compact
documentation:
On WiredTiger,
compact
attempts to reduce the required storage space for data and indexes in a collection, releasing unneeded disk space to the operating system. The effectiveness of this operation is workload dependent and no disk space may be recovered. This command is useful if you have removed a large amount of data from the collection, and do not plan to replace it.
- Context regarding use of compact - E.g. Was a large amount of data removed with no need or plans to replace it?
You may also find the FAQ: MongoDB Storage documentation useful regarding this scenario too. Specific to WiredTiger and deleted documents on the same page:
The WiredTiger storage engine maintains lists of empty records in data files as it deletes documents. This space can be reused by WiredTiger, but will not be returned to the operating system unless under very specific circumstances.
Regards,
Jason