Navigation
This version of the documentation is archived and no longer supported.

db.repairDatabase()

On this page

db.repairDatabase()

db.repairDatabase() provides a wrapper around the database command repairDatabase. See repairDatabase for full documentation.

Behavior

Warning

  • Before using db.repairDatabase(), make a backup copy of the files in the dbpath directory.
  • If you are running with journaling enabled, there is almost never any need to run db.repairDatabase() after an unclean shutdown since the server can use the journal files to restore the data files to a clean state automatically. However, you may need to run db.repairDatabase() in cases where you need to recover from a disk-level data corruption.
  • Avoid running db.repairDatabase() against a replica set. If you are trying to repair a replica set member, and you have access to an intact copy of your data (e.g. a recent backup or an intact member of the replica set), you should restore from that intact copy (see Resync a Member of a Replica Set), and not use db.repairDatabase().
  • You should only use the db.repairDatabase() method (and related repairDatabase command and the --repair command-line option) if you have no other options. These operations remove and do not save any corrupt data during the repair process.

Changed in version 2.6: The db.repairDatabase() is now available for secondary as well as primary members of replica sets.