- Reference >
mongo
Shell Methods >- Database Methods >
- db.repairDatabase()
db.repairDatabase()¶
On this page
-
db.
repairDatabase
()¶ db.repairDatabase()
provides a wrapper around the database commandrepairDatabase
, and has the same effect as the run-time optionmongod --repair
option, limited to only the current database. SeerepairDatabase
for full documentation.
Behavior¶
Warning
During normal operations, only use the repairDatabase
command and wrappers including db.repairDatabase()
in the
mongo
shell and mongod --repair
, to compact
database files and/or reclaim disk space. Be aware that these
operations remove and do not save any corrupt data during the
repair process.
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, and not use repairDatabase
.
When using journaling, there is almost never
any need to run repairDatabase
. In the event of an
unclean shutdown, the server will be able to restore the data files
to a pristine state automatically.
Changed in version 2.6: The db.repairDatabase()
is now available for secondary
as well as primary members of replica sets.