Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't connect to Mongodb running on EC2

I cannot connect remotely to a mongo server running on EC2, even though if I ssh into the server the mongo is running properly. Also note, that the 27017 port is open on both tcp and udp protocols. I am getting the following error:

MongoDB shell version: 2.4.8
connecting to: ec2-x...x-compute.amazonaws.com:27017/test
Thu Sep  4 13:26:04.293 Error: couldn't connect to server to: ec2-x...x-compute.amazonaws.com:27017/test at src/mongo/shell/mongo.js:147
exception: connect failed

I have Mongodb version 2.4.8 on my local host and on the server Mongodb version 2.6.4. Could the version difference be a problem?

like image 908
Pio Avatar asked Sep 04 '14 10:09

Pio


1 Answers

Are you binding to the external IP? Or just localhost:

http://docs.mongodb.org/manual/reference/configuration-options/

net:
  bindIp: 127.0.0.1 # Should be 0.0.0.0 to listen on all interfaces
  port: 27017

Also, I know you said that the port is open. Did you check this using nmap/netcat? You should check the AWS security group and the local firewall to make sure it's open.

like image 172
Daniel Scott Avatar answered Sep 27 '22 21:09

Daniel Scott