Can’t connect to my MongoDB Atlas database with VS Code extension

I am currently struggling to connect to my database through Vscode MongoDB extension.

I used the connection string provided by the ‘Connect’ instructions:
mongodb+srv://test:hello@cluster0.cjsefts.mongodb.net/

But the error I automatically get is the following:
Unable to connect: querySrv EREFUSED _mongodb._tcp.cluster0.cjsefts.mongodb.net

What I have tried

I have check numerous times that my password is the correct, I even tried to change my password but didn’t matter (My passwords didn’t contain any special characters).
I tried to delete the dataabse and create a new one, tried to connect, but got the same response.
Unistall and reinstall Vscode extension.
On my terminal I ran mongostat --uri mongodb+srv://test:hello@cluster0.cjsefts.mongodb.net on my terminal and it succesfully ran, which means the user and password are not the issue.
I used the extension to connect to mongodb://localhost (while previously started mongod server with brew services start mongodb-community@7.0) and it succesfully connected, which means the Vscode extension is not the problem.
I also checked that my IP address was added in the Network Access section I made this with the button ‘Add my IP adress’ when creating the database, I even added the 0.0.0.0/0 to expose the database everywhere in the internet.
I just have one single user named ‘test’ with admin access.
*Restart VScode several times.
I am really stucked and I don’t have any clue what the issue might be. Thanks for your help.

Please check that your system antivirus and firewall can block the connection to MongoDB. Make sure that the port you are using should not be blocked.

1 Like

Just some things I’d try.

The connection seems fine from here.

From what I see in SO and the result of the connection, it could be that your system is querying a DNS that does not understand SRV strings, which have to be mapped to proper connection strings (addresses for each node in the replica set.)

I’m unsure whether the string you receive is the result of the DNS query though.
It’s strange that mongostat works.

But I’d look at these first:

  1. DNS Resolution Issue: check the DNS that you are using (the IP.)

  2. Firewall or Network Restrictions: There could be firewall rules or network restrictions preventing your system from querying the DNS SRV record or connecting to the MongoDB cluster. Make sure that your network allows connections (it may be blocking / not allowing ports like 27017, for example.)