Search code examples
node.jsmongodbexpressamazon-ec2bitnami

MongoDB Connection EC2


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:password@candidate.37.mongolayer.com: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?


Solution

    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.