Connection to the Atlas doesnt give any response

Hello guys. I just started learning working on mongodb atlas with nodejs and i am facing this issue when i try to connect to the cluster . I have enabled connection from anywhere and it still dosent work.

Here is the code and the output:

const MONGO_URL = "mongodb+srv://devcity:vRSGykqKkoM6x7aC@cluster0.8tyidg8.mongodb.net/?retryWrites=true&w=majority";
async function connectandRun() {
  try{
    await mongoose.connect(MONGO_URL)
    console.log("DB COnnected!")
  }
  catch (error){
    console.error("Something went Wrong:",error);
  }
}
connectandRun();

Output:

Something went Wrong: Error: querySrv ETIMEOUT _mongodb._tcp.cluster0.8tyidg8.mongodb.net
    at QueryReqWrap.onresolve [as oncomplete] (node:internal/dns/promises:251:17) {
  errno: undefined,
  code: 'ETIMEOUT',
  syscall: 'querySrv',
  hostname: '_mongodb._tcp.cluster0.8tyidg8.mongodb.net'
}

Your insight would help.Thank you!

Hi @Abhiram_Gargeya,

Your DNS servers are timing out on looking up the SRV records for the cluster. Maybe change your DNS servers.

They resolve fine for me

dig +short  srv _mongodb._tcp.cluster0.8tyidg8.mongodb.net; dig +short txt cluster0.8tyidg8.mongodb.net
0 0 27017 ac-siihb3z-shard-00-00.8tyidg8.mongodb.net.
0 0 27017 ac-siihb3z-shard-00-02.8tyidg8.mongodb.net.
0 0 27017 ac-siihb3z-shard-00-01.8tyidg8.mongodb.net.
"authSource=admin&replicaSet=atlas-10ot4c-shard-0"
1 Like

FYI I’ve written this up in more detail at querySrv errors when connecting to MongoDB Atlas | ALEX BEVILACQUA.

2 Likes

Hey , thanks for your insight . It did work. I changed the DNS server to Google Public DNS and it worked.Thanks once again for such a fast response .

2 Likes

Hey @alexbevi , thanks for the Blog link . It is very informative.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.