I have set up a mongodb Atlas free tier cluster. When I try to connect to it with node js, it throws an error. I have white listed my IP both manually and with select current. I have also tried adding +srv to my connection url but that just causes more errors.
Here is the node js code I was trying to connect with
const { MongoClient } = require("mongodb"); const url = "mongodb://user1:password1!@cluster0-shard-00-00-bc7dh.mongodb.net/test?retryWrites=true&w=majority&useNewUrlParser=true&useUnifiedTopology=true";const client = new MongoClient(url);async function run() { try { await client.connect(); console.log("Connected correctly to server"); } catch (err) { console.log(err.stack); } finally { await client.close(); }}run().catch(console.dir);
and here is the error I get
MongoServerSelectionError: connection to 52.64.0.234:27017 closed at Timeout._onTimeout (C:\Users\YOUNG\node_modules\mongodb\lib\core\sdam\topology.js:430:30) at listOnTimeout (internal/timers.js:549:17) at processTimers (internal/timers.js:492:7)
people with a similar problem were able to solve it by whitelisting their ip addresses, but it hasn't worked for me. What could possibly be the problem?
I have tried allowing access for all ips but the error persists and when I use the uri with +srv, I get the following error
MongoServerSelectionError: Authentication failed.at Timeout._onTimeout (C:\Users\YOUNG\node_modules\mongodb\lib\core\sdam\topology.js:430:30)at listOnTimeout (internal/timers.js:549:17)at processTimers (internal/timers.js:492:7)