MongoDB does not free the disk space for OS use after deleting bunch of documents from the collection. We can reclaim that space using following cases.
- By using compact command - Can be run on collections, but block all orations on database, need small downtime
- By using repaireDatabase - Run on database need extra space and serious downtime
- By dumping database and than drop and restore it - Time consuming and need downtime
- By copy database using temporary name drop original and then re copy with original name - Time consuming and need downtime
Following is the best method of achieve same without downtime on replica set
- Step down secondary server
- Delete database files
- Start server, It will start Replica Set Initial Sync.
- After sync over do the same with other secondary servers one by one
- For primary server step it down.
- Make sure one of the secondary become primary
- Delete database file on primary
- Start primary server It will start Replica Set Initial Sync.
- After Replica Set Initial Sync complete it will become primary as per your replica set configuration
- Done, that's it..
Check used disk space on each server..