Watch keynotes and sessions from MongoDB.live, our virtual developer conference.

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
Warning

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

And

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

  • Rebuilds all indexes.