简体   繁体   中英

MongoDB connection error on AWS ec2 instance

I have trying to connect to my mongo server on ec2 instance from my app hosted on elastic beanstalk.

It worked when authorization was NOT enabled. I could connect through both local IP and public IP.

Then I added users to the DB and enabled authorization in server. I could connect to the server using mongodb://user:password@ec2IP/27017 from any commandline interface.

Using the same mongo URI from the elasticbeanstalk app I cannot connect to the mongodb server. This is the error I am getting -

MongoError: failed to connect to server [<user-name-mongo-server>:27017] on first connect [MongoError: getaddrinfo ENOTFOUND <user-name-mongo-server> <user-name-mongo-server>:27017

Any idea? Thanks in advance!

Apparently,

I had passwords that included either a

%

or a

?

which was the problem for mongoose connection.

so my mongo URI looked like this -

mongodb://<user>:<password-including-%-or-?>@IP:port/dbname

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM