MongoDB won't start on Ubuntu (PHP Exception MongoConnectionException

June 27th 2013

So I just encountered the weirdest thing. You might experience it one day too.

My desktop is set to auto start MongoDB upon boot, which has always worked (for the past 6 months at least)

Interestingly, this morning I fired up my PC to pick up where I left off yesterday. PHP was throwing a MongoConnectionException. The driver couldn't connect to Mongo.

I hit the shell and ran the usual service stop, service start commands, but nothing seemed to work.

Finally, I navigated to the library folder for Mongo. On my system I ran this:

PHP Code:
$ cd /var/lib/mongo
$ ls

The output from the ls command was:

Text Snippet:
journal  mongod.lock  db_test.0  db_test.1  db_test.2  db_test.ns  _tmp

I ran service mongodb stop and then removed the mongod.lock file

Text Snippet:
$ sudo rm mongod.lock

Then restarted Mongo by issuing:

Text Snippet:
$ sudo service mongodb start

Finally Mongo was started back up. Looking into this it seems Ubuntu must not wait for Mongo to shutdown before shutting down the system.

Hope this helps, let me know in the comments or on Google+

MaRya commented on Oct 21st 2013

The setup really helepd me going I am running Ubuntu 9.10 64 bit version The one thing missing in the page is that non root users will not be able to access /data/db directory and mongod will fail to run It needs to be mentioned that by chmod -R 777 /data/db will solve this issue Matt

Roger commented on Nov 16th 2013

@MaRya this is quite possibly the worst thing I've ever seen suggested.

Instead of giving read / write global, look into groups.