0

I'm trying to connect my app running on AWS EC2 to mlab endpoint. I can easily connect using the same code base from my local machine to mlab endpoint. However, when I run on AWS, I get the following error.

{ name: 'MongoError', message: 'connect ECONNREFUSED' }

I have tried increasing connectionTimeMS to 30 seconds, but I still get the same error.

From EC2 instance, I can ping the DB server and netcat is also successful.

My EC2 instance is configured to receive and send all traffic on all ports from any IP address.

I think issue might be related to outgoing traffic, but do not know how to configure.

Thanks

Community
  • 1
  • 1
pkpk
  • 641
  • 1
  • 7
  • 18

1 Answers1

0

Turned out to be environment issue.

I was setting my mlab endpoint using the command

export MONGOLAB_URL='xxxx'

and then running my app

sudo node server.js

this sequence does not set my local environment.

All I had to do in the end was to use the following command

sudo MONGOLAB_URI='xxxxxx' node server.js

pkpk
  • 641
  • 1
  • 7
  • 18