Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB Error couldn't connect to server

Tags:

mongodb

I first execute the command:

sudo service mongodb restart

I get the prompt:

stop: Unknown instance: 
mongodb start/running, process 3175

Then,I execute the command:

mongo

I get the error:

MongoDB shell version: 2.4.6
connecting to: test
Tue Oct  8 19:48:08.961 Error: couldn't connect to server 127.0.0.1:27017 at  src/mongo/shell/mongo.js:145
exception: connect failed

I don't know how I get this error.

like image 208
HXH Avatar asked Oct 09 '13 02:10

HXH


People also ask

Why MongoDB Cannot connect to server?

These are some of the solutions: Ensure that your MongoDB instance is running: Compass must connect to a running MongoDB instance. Also check you have installed MongoDB and have a running mongod process. You should also check that the port where MongoDB is running matches the port you provide in the compass connect.

How do you resolve connect Econnrefused 127.0 0.1 27017?

Then restart the server, and see if it connects. Means that NO mongod instance is running at the given host 127.0. 0.1 and port 27017. Yes the solution is to start mongod.


1 Answers

Execute the following command

sudo rm -rf /var/lib/mongodb/mongod.lock

then

sudo service mongodb restart
like image 105
rand_mem_RAM Avatar answered Oct 20 '22 02:10

rand_mem_RAM