1 year ago
#380464
Sihoon Kim
mongodb atlas and aws lightsail VPC peering seem to work but node.js server still cannot connect
I am trying to establish VPC peering between my AWS server and MongoDB Atlas. Everything looks good on both AWS VPC dashboard side and MongoDB Atlas/Network Access/Peering.
Also if I run the following code in my AWS lightsail Ubuntu terminal
host cluster0-shard-00-01.a7dlx.mongodb.net
, I get the following response: cluster0-shard-00-01.a7dlx.mongodb.net is an alias for ec2-52-201-68-123.compute-1.amazonaws.com. ec2-52-201-68-123.compute-1.amazonaws.com has address 52.201.68.123
So VPC peering seem to work properly. But for some reason I am still getting this connection error in my Node.js application:
MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you're trying to access the database from an IP that isn't whitelisted. Make sure your current IP address is on your Atlas cluster's IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/
Could my Mongo URI be the problem? Maybe I need some special URI for VPC?? I tried both urls:
mongodb+srv://admin:<password>@cluster0.123.mongodb.net/myFirstDatabase?retryWrites=true&w=majority
mongodb://admin:<password>@cluster0-shard-00-00.123.mongodb.net:27017,cluster0-shard-00-01.123.mongodb.net:27017,cluster0-shard-00-02.123.mongodb.net:27017/myFirstDatabase?ssl=true&replicaSet=atlas-gz4wg0-shard-0&authSource=admin&retryWrites=true&w=majority
mongodb
amazon-web-services
amazon-vpc
0 Answers
Your Answer