Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I had mongdb installed and evrything was working fine. I wanted to delete the mongodb lock. By mistake the directory /var/lib/mongodb/ got deleted.

So, I uninstalled mongo db and installed again. But now i always keep getting this error:

Error: couldn't connect to server at src/mongo/shell/mongo.js:145
exception: connect fail

The error remains same even if I try to login from terminal or rockmongo or my application. I am using ubuntu12.04 and have latest version of mongo.

share|improve this question
Have you seen this =>… – Achu Nov 26 '13 at 6:00
Yes..but in my /var/lib/mongodb there is no mongodb.lock. – Sankalp Mishra Nov 26 '13 at 6:01
The file could be in a different path or it could be named mongo.lock – Achu Nov 26 '13 at 6:05
What you get when you run this /usr/local/mongodb/bin/mongod? – Achu Nov 26 '13 at 6:11
I get bash: /usr/local/mongodb/bin/mongod: No such file or directory – Sankalp Mishra Nov 26 '13 at 6:12
up vote 2 down vote accepted

You get the connect failure because the server is not running. Run this:

sudo service mongodb restart

If that does not succeed then you will need to examine the log files for the server to see what is stopping it from starting. You can find the log in /var/log/mongodb/mongod.log and if it is not an obvious cause, then please add the relevant snippet to your question and I'd be happy to take a look.

If I were to guess based on your description, I would suspect you did not set the correct permissions on /var/lib/mongodb - when you recreated it. It should look like this:

drwxr-xr-x 4 mongodb mongodb 4096 Nov 26 18:52 mongodb

If it has incorrect permissions, then you can fix it with the following command:

sudo chown -R mongodb:mongodb /var/lib/mongodb
share|improve this answer
mongod not mongodb ? – Eduardo Dennis Sep 25 '14 at 1:16
that depends on what package you use to install, it can be either but it is generally one or the other – Adam C Sep 25 '14 at 1:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.