I upgraded to M2: Mongoose Server Selection Error: Could not connect to any servers in Atlas


I just upgraded to M2. On my localhost I can connect to the database.

On my vServer, the connection does not work anymore. It worked before without any flaws.

The error message varies between:

  • Mongoose Server Selection Error: Could not connect to any servers in Atlas
  • getaddrinfo ENOTFOUND cluster0-shard …

What I already did:

  • Specifically opened Port 27107 (I can ping it without issues)
  • Whitelisted the correct IP (for testing purposes all IPs)
  • Created a new user with new credentials (works on my local machine, but not on the server as well).
  • Tried the old version of the Connection String (nodeJS 2.2)

I use the following string:


Hi @Malte_Hoch and welcome in the MongoDB Community :muscle: !

From the same machine you are trying to connect to your M2 from, can you connect using Mongosh?

mongosh "mongodb+srv://free.ne23r.mongodb.net/myFirstDatabase" --apiVersion 1 --username max

Do you happen to have a firewall or some antivirus in place maybe? Maybe a company policy that blocks the port 27017?


Hey @MaBeuLux88,

First of all, thank you for your prompt reply. I could solve the issue by removing “?retryWrites=true&w=majority” from the string. Quite weird, since this worked perfectly fine before the upgrade to M2 and I would have never expected this to be the final solution after investigating the docs, this forum and Stackoverflow! :slight_smile:

Thank you for your hint anyway.

With best regards


I just used the “CONNECT” button in Atlas and follow the path for the application I want to use. Then I just copy & paste the command line or the connection string that is provided.


This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.