`cannot connect to mongoDB

sorry if the category is not right, i am new to mongoDB that is why i know about the much.
the problem I encountered is this :

ERROR (payload): Error: cannot connect to MongoDB. Details: querySrv ECONNREFUSED _mongodb._tcp.cluster0.ejctebw.mongodb.net

i do not understand why i am getting error, i have try with three new id but getting same error.

this is my connection string : mongodb+srv://:@cluster0.ejctebw.mongodb.net/?retryWrites=true&w=majority

i have written correct name, password and database name.
i have try with database name and without database name in my connection string.

can anyone help me regarding this issue. i have try the Stackflow answer and also try to implement
like IP addresss , allow from anywhere, delete and create IP address along with
i have check my driver which is node with latest version.

I am trying to connect mongo application and also check user name and password.
i have also try creating database under collection, try every way i but nothing resolve my error

Hello , Can you please check all IP details added in whitlist(security/network access) ? this seems DNS not resolving the server validation . let me know if it helps

i have verify my IP detail. also change my network connection. nothing work

Try using as DNS server.


make sure you PC/laptop is not performing any restriction from firewall perspective, also check your anti-virus on your PC.

can you tell me use i an apply this ?

i have cross checked it, nothing changed


@raj_gupta3 this is a DNS issue (see querySrv errors when connecting to MongoDB Atlas | ALEX BEVILACQUA for more details).

If you go to the connect modal for your cluster and choose an older version of the Node driver (ex: 2.2.12 or later) it’ll give you the legacy connection string:

Using the legacy mongodb:// protocol as opposed to the mongodb+srv:// protocol will allow you to avoid the additional DNS queries that appear to be failing.


Actually you are correct it seems its DNS issue. facing the same problem when trying to connect to Atlas from my machine.
when checking my windows event log -----> System
the following was thrown:
Name resolution for the name myatlasXXXXX.XXXXX.mongodb.net timed out after none of the configured DNS servers responded.

Emad Al-Mousa

I am having a similar problem which I cannot seem to track down.
Local Compass is connected with the Atlas Cluster and I can edit in either.
But the AI Generate Query which brings up a modal to connect then fails with this message:-

Sign in failed
listen EADDRNOTAVAIL: address not available fe80::1:27097

I don’t understand that message apart from an address is not available.
Can anyone help me with this?

Thanks, this is what I have:-

Atlas MongoDB Cloud
Data Services / Network Access (includes your current IP address) Current Active

I will check through my local configuration later; this error looks like it needs IP6 and a particular port to be open.

why database connected on 2.2.12 version but on latest driver version it gives error of Error: queryTxt ETIMEOUT cluster0.______.mongodb.net

1 Like

The connection string for 2.2.12 uses the Standard Connection String Format (ex: mongodb://) whereas the later versions of the driver would present the SRV Connection String Format (ex: mongodb+srv://).

The SRV format requires 2 DNS queries to be performed (an SRV query and a TXT query), the results of which are used to construct a standard connection string formatted string that is used by the drivers to establish a connection to the cluster.

If those DNS queries fail, connection string construction will fail and you’ll typically get an error such as querySrv ETIMEOUT or queryTxt ETIMEOUT.

1 Like

how can i connect through latest version too, i have fix the DNS problem too like and the other one in adapter settings in ipv4 properties but it was not the issue in my case

You can use the standard connection string format with the latest driver. The UI in Atlas is a little misleading (we’re working on improving this) as it makes it seem as though you need to use an older driver to use the older connection string format - which isn’t true.

Just select 2.2.12 from the UI to get the mongodb:// connection string then use that to connect using the latest Node.js driver.

1 Like

i selected 2.2.12 and used connection string of 5.5 it not worked same error again , only the connection string of 2.2.12 is working …

Correct - if you’re having a DNS issue resolving the SRV record then you’d need to use teh 2.2.12 connection string with 5.5. The difference is one connection string begins with mongodb:// and the other begins with mongodb+srv://.

The first one doesn’t require DNS queries, which is why you wouldn’t see the associated errors.

1 Like

sir from where i can get the info of correcting dns ? i set the dns in the pic attached but for me it not worked