Unable to connect to MongoDB

You must specify the IP (199.21.114.XX), by running mongo 199.21.114.XX.

Otherwise, if you want it to listen on localhost as well, you should remove the bind_ip setting in your config file.

Update Check your firewall config. Since you're connecting to the external IP, it can be configured to block, even from the local box.


I had the same issue just because the silly mistake.

first remove mongodb file which is fine

rm -rf /tmp/mongodb-27017.sock

where I did mistake inside the /etc/mongod.conf

# network interfaces
net:
  port: 27017
 #bindIp: 127.0.0.1
bindIp: privateIp

instead of

net:
  port: 27017
  bindIp: 10.1.2.4

for listen to all available ips

bindIp: [127.0.0.1,10.128.0.2]

restart the mongodb

sudo service mongod start

hopefully this answer help for someone


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

I solved this problem by commenting out the following line in my /etc/mongod.conf file.

# Listen to local interface only. Comment out to listen on all interfaces. 
#bind_ip = 127.0.0.1

You will need to follow this config change with restarting the mongod process.

sudo service mongod restart