Atlas-cluster connection error

had an error today to connect my node js project to atlas, 
currently I'm on cluster level M0 (free)
node js v18.12.1
"express": "^4.18.2",
"mongodb": "^5.8.0",
"mongoose": "^7.4.4",

mongoose.connect('mongodb+srv://<username>:<password>', {
          useNewUrlParser: true,
          use UnifiedTopology: true,

get this error message:

Error: queryTxt ETIMEOUT
       in QueryReqWrap.onresolve [as done] (node:internal/dns/promises:251:17) {
     errno: undefined,
     code: 'ETIMEOUT',
     system call: 'queryTxt',
     hostname: ''

someone please help me to solve this error, its taking my time and effort a lot.

best regards

Hi @Dani_Haldi, Welcome to the mongo community.

It looks like you don’t put your username and password on your connection string.

If you don’t have a user and password yet, can be good to look at this docs. Here is the explanation about create a user on atlas.

After get your username and password, put these values in your connection string exactly where is <username> and <password>. If you have more questions about connection strings, can be helpful access this docs.

I have entered the username and password correctly but the error always appears as I explained

Looks to be a DNS related error. Try a different DNS for troubleshooting purposes.


I’ve tried what you suggested, and still get the same error :pensive:

Can you share more details on:

  1. How you changed the DNS (and to what value)
  2. Was the application restarted after changing the DNS settings
  3. The environment in which the application is run (OS details, containerised, virtualised, etc)
  4. If from the same client you can connect using mongosh or MongoDB Compass

Additionally it may sound odd but we can’t rule it out completely, please verify you’re using the correct connection string. Check using the connection string procedure in the Atlas UI. I’ve seen some cases people created a cluster, copied that particular string, deleted said cluster then created a new one forgetting to get the new connection string.