Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused

Ashish Ranjan picture Ashish Ranjan · Oct 6, 2014 · Viewed 172.7k times · Source

while trying this mongo command in ubuntu I am getting this error.

    ritzysystem@ritzysystem-Satellite-L55-A:~$ mongo
    MongoDB shell version: 2.6.1
    connecting to: test
    2014-10-06T12:59:35.802+0530 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
    2014-10-06T12:59:35.802+0530 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
    exception: connect failed

how can I rectify this is anyone had the same problem.

Answer

Jagdish Barabari picture Jagdish Barabari · Dec 4, 2014

Run the following command :

sudo rm /var/lib/mongodb/mongod.lock
sudo service mongod restart

Connection refused to MongoDB errno 111

MacOS:

rm /usr/local/var/mongodb/mongod.lock  
sudo service mongod restart