Can Mongodb repair database without rebuild indexes?

For a unknown reason, my mongodb has been stopped unexpectedly.

When i try to restart my Mongodb, it told me to use --repair to fix my data.

but some of my data are having huge indexes, how can i repair my data without rebuild indexes?

Have you looked at the logs to move the reason from unknown to known.

Because until they are known and corrected you should expect that it might stop unexpectedly again.

And as indicated in the manual page

Only use mongod --repair if you have no other options. The operation removes and does not save any corrupt data during the repair process.


Starting in MongoDB 4.0.3, for the WiredTiger storage engine, mongod --repair :

  • Rebuilds all indexes.

I am using v5.0.5. The daemon works fine for me but I should be ready for the case when the database server goes down for some reason and I have to restart it for a very large database. I have applications running which can’t wait for hours just for database restart.

Is there any way I can start the mongod service and keep the index rebuilding in the background or just completely ignore the index rebuild in v5.0?

In older versions, there was indexBuildRetry option in mongod.conf.


Please read the documentation at

Welcome to the MongoDB Community Forums @Anuj_Gupta2 !

You should use a replica set to provide high availability and data redundancy for a production deployment. Replica sets also provide administrative convenience to avoid or minimise downtime based on the fault tolerance for your deployment topology.

mongod will automatically recover using the journal after an unclean shutdown and does not need to rebuild indexes. If you have disk-level data corruption that cannot be automatically recovered from, you would ideally resync from a healthy member of the same replica set.

If you are running a standalone deployment and have disk-level corruption that prevents startup, you should start by reverting to a recent backup.

If you have no other options, mongod --repair is a last resort which tries to salvage data that can be read. Per the highlighted warning on Recover a Standalone after an Unexpected Shutdown:

Only use mongod --repair if you have no other options. The operation removes and does not save any corrupt data during the repair process.

The same page also has a note on not needing to run repair manually:

If you are running with journaling enabled, there is almost never any need to run repair since the server can use the journal files to restore the data files to a clean state automatically. However, you may need to run repair in cases where you need to recover from a disk-level data corruption.

This option related to retrying interrupted index builds, since foreground index builds blocked read-write operations to the parent database in MongoDB 4.0 and earlier. The index build process was improved in MongoDB 4.2 so there are no longer blocking foreground index builds per Index Builds on Populated Collections.



This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.