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.

There is already an issue related to this is listed.
You can refer to it, it may help.

Hi MongoDb Support Team, I have similar issue where Despite the successful upgrade, we are encountering issues with establishing a connection to MongoDB from the IIS server. Previously, the connection string in the appsettings.json file utilized the complete replica set connection string. However, attempts to connect using the full connection string result in a timeout error after 30,000ms.

Observed Differences:
Upon further investigation, we noticed a disparity between the member configuration in the MongoDB replica set from the old setup to the new one. Specifically, the application seems to be attempting connections using the headless service, which is causing connectivity issues.

Request for Assistance:
We seek your expertise in resolving this connectivity issue and optimizing the connection string to ensure seamless communication with the MongoDB replica set. Our objective is to enable the application to establish connections using the complete replica set connection string, similar to the previous setup, thereby ensuring robust and reliable connectivity.

Your insights and assistance in addressing this matter would be greatly appreciated. Please feel free to reach out for any further clarification or collaboration required from our end.

Upgrade Details:

Modules and charts across xxxxx-Infrastructure were upgraded to ensure compatibility and prevent any deprecated functionality.
Following the upgrade, the MongoDB version was advanced from 4.2.3 to 6.0.10, along with Helm chart version 13.18.5.

Subject: Issue with MongoDB Connection from IIS Server Post-Upgrade

Dear [Application Team],

I hope this message finds you well. I wanted to provide you with an update following our today’s discussions regarding the upgrade of all modules and Helm charts in the xxxxx-Infrastructure environment.

I’m pleased to reiterate that all modules and charts within xxxxx-Infrastructure on QA environment were successfully upgraded, overcoming various challenges along the way.
This upgrade was essential to ensure compatibility, address potential issues, and eliminate any deprecated charts and Modules.
However, despite the successful upgrade, we have encountered a minor challenge related to connecting to MongoDB from the IIS server post-upgrade.

The MongoDB version was advanced from 4.2.3 to 6.0.10, alongside Helm chart version 13.18.5.

Our primary concern now revolves around establishing a connection to MongoDB from the IIS server. Despite our efforts, we are facing difficulties connecting to MongoDB using the complete replica set connection string.
Attempts to do so result in a timeout error after 30,000ms.
This is the connection string which is there always and used to connect with replicaset in old version.
“EnrichmentCluster”: {
“ConnectionString”: “mongodb://mongo-0.xxxx:27017,mongo-1.xxxxx.local:27017,mongo-2.xxxxx.local:27017/MCUploadAssistantDatabase?connect=replicaSet&replicaSet=rs0”,
“CollectionName”: “EnrichmentClusters”
},
“UploadedFiles”: {
“ConnectionString”: “mongodb://mongo-0.xxxxx.local:27017,mongo-1.xxxxx.local:27017,mongo-2.xxxxx.local:27017/MCUploadAssistantDatabase?connect=replicaSet&replicaSet=rs0”,
“CollectionName”: “UploadFiles”
},
“ValidationLog”: {
“ConnectionString”: “mongodb://mongo-0.xxxxx.local:27017,mongo-1.xxxxx.local:27017,mongo-2.xxxxx.local:27017/ValidationLog”,
“CollectionName”: “ValidationLog”
}
},

Now we have changed the connection string as mentioned below then only it connects which is not ideal condition.

Mongo": {
“EnrichmentCluster”: {
“ConnectionString”: “mongodb://mongo-0.xxxxx.local:27017/MCUploadAssistantDatabase”,
“CollectionName”: “EnrichmentClusters”
},
“UploadedFiles”: {
“ConnectionString”: “mongodb://mongo-0.xxxxx.local:27017/MCUploadAssistantDatabase”,
“CollectionName”: “UploadFiles”
},
“ValidationLog”: {
“ConnectionString”: “mongodb://mongo-0.xxxxx.local:27017/ValidationLog”,
“CollectionName”: “ValidationLog”
}
},