Repair MongoDB

In case MongoDB crashes and you cannot start it again without errors, you need to repair the data files.

To do this, you can use the following repair command:

mongod --dbpath /data/db --repair

Note: You can include the --repairpath option to specify an alternate temporary directory.

When completed, the dbpath should contain the repaired data files and an empty mongod.lock file. If you want your current database to be replaced by the repair, you can use your current dbpath after the —dbpath flag.

In case repair is not working

  • When the database has crashed, some data is stored in its journal. This is recovered on startup of the database. Ideally, shut down CLOUDFLOW, start MongoDB and stop it again cleanly before doing a repair.
  • Repair MongoDB doesn’t work with journaling enabled. In case you defined a config file in the repair command containing the following lines, you need to remove them:
    journal:
              enabled: true

    After MongoDB is repaired, it will start and launch with Journal in case it is the default behavior. Nevertheless, the default is without journaling.