How to repair my mongodb?

I can't seem to connect to Mongo DB, which I've installed as a Windows Service on my local machine. I've also built a little WPF application which communicates with MongoDB. The errormessage:

Error: couldn't connect to server 127.0.0.1 shell/mongo.js:8 4 exception: connect failed Unclean shutdown detected.


Solution 1:

You should launch it with --repair flag.

mongod --repair

After repair is finished, stop this one and launch it normally. Documentation on --repair option.

Solution 2:

Quicker:

sudo rm /data/db/mongod.lock
sudo mongod --dbpath /data/db --repair
sudo mongod --dbpath /data/db

Solution 3:

If you do a repair operation as root user be sure that afterwards all db files are owned by the mongodb user, otherwise mongodb will not start

chown -R mongodb:mongodb /data/db
rm /data/db/mongod.lock
/etc/init.d/mongodb start

Solution 4:

$ mongo 
> use dbname
> db.repairDatabase()

Note --repair functionality is also available in the shell with the db.repairDatabase() helper for the repairDatabase command.

See also http://docs.mongodb.org/manual/tutorial/recover-data-following-unexpected-shutdown/: