Mongodb can't connect to localhost but can connect to localhost's IP address Mongodb can't connect to localhost but can connect to localhost's IP address mongodb mongodb

Mongodb can't connect to localhost but can connect to localhost's IP address


Do you have a bind_ip set in your mongodb.conf (or startup script)? edit for clarity A bind_ip setting limits the IP it will listen on to that IP only.

See the IP Address Binding section: http://www.mongodb.org/display/DOCS/Security+and+Authentication

If not, do you have any firewall rules blocking the localhost access? That would be kind of strange, but I can't think of another reason why it wouldn't work while the LAN IP would work.


This error could also appear if mongodb was not properly shutdown. If you type sudo start mongodb and if it gives a new process id on every execution then your mongodb was not properly shutdown. To resolve this type

sudo rm /var/lib/mongodb/mongod.locksudo -u mongodb mongod -f /etc/mongodb.conf --repair sudo start mongodb


Just follow all these steps to solve this problem

Step 1: Remove lock file.sudo rm /var/lib/mongodb/mongod.lockStep 2: Repair mongodb.mongod --repair Step 3: start mongodb.sudo start mongodb orsudo service mongodb startStep 4: Check status of mongodb.sudo status mongodb or   sudo service mongodb statusStep 5: Start mongo console.mongo