Unable to connect to mongo atlas on my local environment

hi everyone, hope u are doing fine. I tried connecting to mongo atlas on nextjs, i followed the tutorial from How to Integrate MongoDB Into Your Next.js App | MongoDB
after putting the env variables, and running yarn dev, i get the following error:

Error: querySrv ETIMEOUT _mongodb._tcp.djamelcluster.mqvig3i.mongodb.net
at QueryReqWrap.onresolve [as oncomplete] (node:internal/dns/promises:251:17) {
errno: undefined,
code: ‘ETIMEOUT’,
syscall: ‘querySrv’,
hostname: ‘_mongodb._tcp.djamelcluster.mqvig3i.mongodb.net’

as for the env variable, i did set in the correct username and password as well as put in the database name.
and i also added my ip address to the network access section of the mongo atlas (i added so that it can be accessed from anywhere)

i did try to delete the cluster and initialize another one, but the problem still persists, it’s seems to be an issue with my internet or something like that.

any suggestions on how i can fix this issue?

Hi @Djamel_Abbou and welcome to the MongoDB community forum!!

The error mentioned looks like an srv lookup failure.

Could you try using the connection string from the connection modal that specifies all 3 hostnames instead of the SRV record?
You can follow the steps below to get the connection URI.

  • Click Connect on the cluster you wish to connect to
  • Select Connect your application
  • Choose Node.JS for the Driver option
  • Choose the Version 2.2.12 or later for the version option

You can follow the documentation on Set up your Atlas cluster to make sure you are using the right steps to set up the cluster.

You can also follow the documentation on Atlas troubleshoot Connection issue documentation for more information.

Lastly, can you confirm, if you are able to connect to the Atlas cluster outside the application using Shell or Compass.?