Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect to MongoDB EC2 instance

Tags:

we have an EC2 MongoDB 2.4 instance from Amazon MarketPlace. when i try to access it from my computer using the mongo command like so:

mongo xx-xx-xx-xx-xx.compute-1.amazonaws.com

i get the following error

Error: couldn't connect to server xx-xx-xx-xx-xx.compute-1.amazonaws.com:27017 at src/mongo/shell/mongo.js:147
exception: connect failed
  • i can connect to the remote instance using ssh so it is reachable.
  • the port is the default port 27017.
  • mongod is running and working on the remote instance.

any suggestions on how to fix this?

like image 420
user2708100 Avatar asked Nov 24 '13 14:11

user2708100


People also ask

Does MongoDB run on EC2?

MongoDB can be installed on Amazon EC2 or deployed using the AWS Marketplace. First, you will need to get your deployment planning and set up the single production node. This will be followed up with setting up a place for storage before getting your MongoDB instance running.

How do I access MongoDB remotely?

MongoDB can be managed remotely or connected to a separate application server by making a few changes to the default configuration. First, we'll install the MongoDB using the docker container, then configure the MongoDB installation to access from a trusted remote machine securely.


1 Answers

As frisky said, you have to open the port 27017 at the EC2 Security Group Console. (To know more about how to do that: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/authorizing-access-to-an-instance.html)

But you also need to change the bind_ip variable at the /etc/mongodb.conf file. You need to comment the line or assign the ip that will be able to connect the DB to it.

like image 159
Jundiaius Avatar answered Oct 26 '22 12:10

Jundiaius