Hello,
I have mongodb replicaset with one primary and two secondaries (running as statefulset in K8s). Few days ago when running tests, the disks went full. After allocating more diskspace we managed to get mongodb back to running. Then we deleted with ‘deletemany’ documents from the db. This did not reclaim the disk, as the compact is needed to run.
But, when running the compact, I cannot use loop in secondaries, like:
So I cannot loop trought all the collections. Also I need to run the compact commands per collection, on all nodes. First on secondaries then change primary to secondary and there as well.
Is this the correct process, is what I am thinking.
Yes deletemany is the correct way to remove documents from your collection.
If you are going to run the compact command then you do it as you’ve outlined. First on the secondaries and then step down the primary and run on that node as it’s a secondary now.
The other method @chris mentioned is doing an initial sync on each node after doing the delete many. Because if you delete the data and journal files when the data is replicated it’ll only claim the space used by the documents.