Can't connect to mongodb.Could not connect to any servers in your MongoDB Atlas cluster

while trying to connect with mongodb i’m getting this error :

MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. One common 
reason is that you're trying to access the database from an IP that isn't whitelisted. Make sure your current IP address is on your Atlas cluster's IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/
    at NativeConnection.Connection.openUri (D:\Node-Jonas\Node-Projects\node_modules\mongoose\lib\connection.js:828:32)
    at Mongoose.connect (D:\Node-Jonas\Node-Projects\node_modules\mongoose\lib\index.js:335:15)
    at Object.<anonymous> (D:\Node-Jonas\Node-Projects\server.js:21:4)
    at Module._compile (internal/modules/cjs/loader.js:1138:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
    at Module.load (internal/modules/cjs/loader.js:986:32)
    at Function.Module._load (internal/modules/cjs/loader.js:879:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47 {
  reason: TopologyDescription {
    type: 'ReplicaSetNoPrimary',
    setName: null,
    maxSetVersion: null,
    maxElectionId: null,
    servers: Map {
      'cluster0-shard-00-00-g4ttz.mongodb.net:27017' => [ServerDescription],
      'cluster0-shard-00-01-g4ttz.mongodb.net:27017' => [ServerDescription]
    },
    stale: false,
    compatible: true,
    compatibilityError: null,
    logicalSessionTimeoutMinutes: null,
    heartbeatFrequencyMS: 10000,
    localThresholdMS: 15,
    commonWireVersion: null
  }
}

i already whitelisted my ip but still getting the problem.also can’t connect to compass. it was all fine even yesterday and so don’t know why all of suuden this problem occured.need help.Thanks

17 Likes

i have same problem :frowning:

11 Likes

I have the same problem

5 Likes

The IP address seen by Atlas is not necessarily the IP address of your workstations. If behind a router that does NAT or using VPN the address seen is the one of the router or the exit point of the VPN.

First try to Allow Access From Anywhere. If it works it is most likely because you whitelisted an IP address that is not your public address. Find your public IP with https://www.whatismyip.com/.

If the above does not work then we need more information to help.

37 Likes

What additional information can I provide?

I also have my IP whitelisted, checked it against the whatismyip, and enabled Allow Access From Anywhere. I still cannot connect.

I have also tried resetting the password, making a new user, making a new project/database/user and none of them can connect, either.

It is strange because it was working yesterday, I installed regex, did an audit for a red vulnerability alert, and shortly thereafter it stopped and I have not been able to connect since.

ETA: I did a stash and the issue does seem to be something that happened when I npm installed a package and did the audit; the file w/strings is in .gitignore but I am able to connect now.

7 Likes

I am also facing the same problem.

2 Likes

Have you checked with MongoDB support? Are these issues continuing?

1 Like

well I have faced same problem on Atlas : MongoDB …so than I went to network access section and then edit it again nd set my current id address again …It worked !! I don’t know its permanent solution or what but it may helpful to you.

51 Likes

thanks @Depak_dadlani this worked for me

6 Likes

yes worked for me. Thankss

I have the same problem, tried all the above but still not working. any other ideas?

5 Likes

I have same problem. I 'm trying from c-panel, running script to connect atlas server, even though my IP is whitelisted. Can anyone help me on this please…

4 Likes

Hi @111542 @Pavan_Naik1 (and anyone else who is having trouble connecting to their cluster),

There are many different causes for issues connecting to clusters. For the community to best help you, please start start new discussions topics with more details of your environment including:

  • deployment type (standalone, replica set, or sharded cluster)
  • if the deployment is on-premises or a managed service (eg MongoDB Atlas)
  • the specific client/driver version you are trying to connect with and any error messages returned
  • steps you have tried to resolve your connection issues

A good starting point is the documentation guide to Set Up Atlas Connectivity.

You may also find this previous forum discussion helpful: Error: couldn't connect to server 127.0.0.1:27017 - #16 by Stennie.

Thanks,
Stennie

4 Likes