We are facing space pressure on production server so we are planning to reclaim space from prod instance.replication is there ,can anyone help me to know complete process in sequence to reclaim free space.

I am thinking to use repair db commend at slave node to reclaim space but don't know how to make secondary node after repairing to primary server and start replication again.

  • I didn't get the last paragraph completely. If you want to claim the free space, use compact command, but this holds a lock on the db level. Else, you can mongoexport the current database files to another computer being installed with mongo and import the same data using mongoimport command. Post importing the data, stop the mongod node and replace with new database files.
    – harshavmb
    Jan 6 '16 at 15:04
  • Compact will only free space if you are using WiredTiger, so it would be helpful if you would mention what version and storage engine was being used here
    – Adam C
    Jan 7 '16 at 17:06

Once and for all: The database repair command is potentially harmful and is advised against

You should not use repairDatabase for data recovery unless you have no other option.


This command obtains a global write lock and will block other operations until it has completed.

Hardly what you want in a production system. I already answered a similar, though not identical question. However, the same rules apply. Read the part on capacity planning closely.

And honestly: if you have to ask for the procedure, you really, really, really should not even think about executing it. Even when you get a detailed How-To, you will lack any knowledge of potential side effects. If it is a production system, get yourself a DBA. It is worth it.


you can use repair db command for availing space. As you have mentioned that you are using replica set so you can repeat below steps (I am assuming that you are using 3 member replica set):

  1. Stop one of your secondary and start it on some other port and do db repair.
  2. Now restart your secondary with old port with replset option.

Repeat it for remaining secondary.

For primary ,you can step it down to secondary using "rs.stepDown" and then perform above mentioned steps. But before you start doing this make sure you have available space in your Db it should be equal to same as db size + 2GB.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.