MongoDB won't start after server crash MongoDB won't start after server crash mongodb mongodb

MongoDB won't start after server crash


The log file is telling you that you have an "old lock file". MongoDB keeps a lock file while it's running. It creates this file when it is started, and deletes it when it's stopped. When the computer crashes (or MongoDB crashes, e.g. via kill), this file is not deleted, and thus the database does not start. The existence of this file indicates unclean shutdown of MongoDB.

Two things can be done:

  1. If this is a development machine and you haven't been using your database (and neither have your programs), you can remove the file manually. For MongoDB 2.2.2 running on Ubuntu 12.10, it's in /var/lib/mongodb/mongod.lock. For other versions, the file could be in a different path or it could be named mongo.lock.

  2. The safer route is to follow MongoDB's Durability and Repair guide. In summary, for a machine with the above configuration, you should execute the following commands:

    sudo -u mongodb mongod --repair --dbpath /var/lib/mongodb/sudo service mongod start


all I had to do was run:sudo mongod --repair

then:

sudo mongod


Based on my experience, I usually delete the "mongod.lock" file that is inside the database folder - In my case:

*I browse to where the database is installed on my ubuntu i.e. "data" folder.(cd data); list the files (ls)*Then, I will remove the "mongod.lock" file that was automatically created when the database crashed, by issuing "rm mongod.lock" file.

After which I will either issue "./mongod" to start the mongo deamon or mongo to start the mongo shell. And everything will be fine.