MongoDB Connection EC2

5.3k views Asked by At

I just setup a MongoDB instance to be running in EC2 using the Bitnami MEAN stack. I am trying to connect to the MongoDB instance in my node application, but I don't know what the URL path would be.

I am familiar with paths that look like this:

mongodb://username:[email protected]:port/database

But am unclear how I would figure out what the equivalent path is for my EC2 instance. I found that there is a mongodb-27017.sock file in one of the directories, but the below didn't work.

mongodb://{USERNAME}:{PASSWORD}@{EC2LINK}/stack/mongodb/tmp/mongodb-27017.sock/{DATABASENAME}

Is there any way to figure out what the path is?

2

There are 2 answers

9
Reut Sharabani On BEST ANSWER
  1. Make sure mongo service is running: service mongod status
  2. Make sure the port is open in the security group. (mongo defaults to 27017)
  3. Use this connection URL (same as you're used to): mongodb://{USERNAME}:{PASSWORD}@{EC2 INSTANCE IP / HOSTNAME}/{DATABASENAME} . See Examples

Note: changing the port would require specifying it in the connection string.

0
Ahmed Haque On

Thanks for the help Reut, your suggestions helped me to narrow things down. (I wasn't completely off track).

I finally figured out that my issue was I needed to change the bind_ip config variable in my mongodb.conf file. The bind_IP variable was set (by default) to 127.0.0.1. This prevents remote connections from making their way to the db.

I've since changed that to 0.0.0.0 to allow remote connections.