Unable to connnect to my MongoDB Atlas

Error: queryTxt ETIMEOUT cluster0.xxxxxxx.mongodb.net
    at QueryReqWrap.onresolve [as oncomplete] (node:internal/dns/promises:252:17) {
  errno: undefined,
  code: 'ETIMEOUT',
  syscall: 'queryTxt',
  hostname: 'cluster0.xxxxxxx.mongodb.net'
}

when i connect to my atlas it giving this error and i have no idea what its about so i cant debug it, it just happened suddenly coz it was working okay before all this

here is how am connecting to the atlas:


const connect = async () => {
  try {
    await mongoose.connect(process.env.MONGODB_URI, {
      useNewUrlParser: true,
      useUnifiedTopology: true,
    });
    console.log('Connected to mongoDB Atlas!');
  } catch (error) {
    console.log(error);
  }
};
connect().then(() => {
  try {
    app.listen(process.env.PORT, () => {
      console.log(`Server running on port ${process.env.PORT}`);
    });
  } catch (error) {
    console.log(error);
  }
});

here is my URI:

MONGODB_URI = mongodb+srv://yyyyyyyyy:xxxxxxxxxx@cluster0.gdrr9qe.mongodb.net/?retryWrites=true&w=majority

Hi @iSteven_Zion_N_A,

Welcome to the MongoDB Community :star2:

It seems like the DNS issue, try using Google’s DNS 8.8.8.8 and 8.8.4.4. Also, you can refer to one of responses here to learn more about it.

In case you’re still encountering further issues whilst connecting, please provide any error messages received.

Best regards,
Kushagra

hi, i’ve followed your instruction but still not worked.
besides, i have had connected before using the same network from my phone hotspot.

cronologhy:
when i mistakenly imported my user model (not included .js when importing it!), so my entire server got off, ofcourse my atlas mongoDB too. Because i used this command: “node --env-file .env --watch index.js” to activate both of it.

after correcting my mistake (by added .js on my user.controller) so i tried restart it again. but unfortunatelly i got that error msg from my terminal.
i did follow your steps, changed my dns from my network properties at ms windows control panel.

So, is my step incorrect or there is a solution for this issue? thanks in advance for the response @khusagra_kesav

Hey @iSteven_Zion_N_A

Did you access Mongo Atlas through Mongo Shell with same uri? If yes, can you access it ?

Also, you can see the option “Network Access” in the Mongo Atlas menu. Can you see any ip address on the list?