Mongodb Repair

These are the commands to do an offline repair of a Mongodb database. Bear in mind this process is destructive (Eg if it finds an invalid entry it will be removed).

The repair process

First stop the mongodb service (if running)

service mongodb stop

Now run the repair (Adjust the dbpath as required..)

mongod --dbpath /data/db --repair

Check permissions on the files in /data/db. If they have changed to root / camuser and start Mongo again

chown -R mongodb:mongodb /data/db
service mongodb start

Tail the mongodb logs to confirm it has started correctly

tail -f /var/log/mongodb/mongodb.log

Any comments or questions? Get in touch here or Email me at [email protected]