Mongo server selection error

Can someone help? I am getting this error.


May Node me with you
listening on 3000
MongoServerSelectionError: Server selection timed out after 30000 ms
    at Timeout._onTimeout (/Users/melle/Desktop/crud for demo/node_modules/mongodb/lib/sdam/topology.js:293:38)
    at listOnTimeout (node:internal/timers:559:17)
    at processTimers (node:internal/timers:502:7) {
  reason: TopologyDescription {
    type: 'ReplicaSetNoPrimary',
    servers: Map(3) {
      'ac-r8gp4rs-shard-00-01.adm9hgw.mongodb.net:27017' => [ServerDescription],
      'ac-r8gp4rs-shard-00-00.adm9hgw.mongodb.net:27017' => [ServerDescription],
      'ac-r8gp4rs-shard-00-02.adm9hgw.mongodb.net:27017' => [ServerDescription]
    },
    stale: false,
    compatible: true,
    heartbeatFrequencyMS: 10000,
    localThresholdMS: 15,
    setName: 'atlas-wpmlmp-shard-0',
    maxElectionId: null,
    maxSetVersion: null,
    commonWireVersion: 0,
    logicalSessionTimeoutMinutes: null
  },
  code: undefined,
  [Symbol(errorLabels)]: Set(0) {}
}

Hi @Jamelle_Mobley and welcome to the MongoDB Community forums! :wave:

It looks like you’re attempting to connect to an Atlas cluster using code written in Node.js and are getting a timeout. Have you made sure that you have allowed access to the Atlas cluster from the machine that’s running the code? Can you connect via the mongosh command line tool?

1 Like

I recreated everything, even a new account just incase I did something wrong. I even tried compass and still get the same problem. I added and deleted the IP address more than once and it is still not working.

Were you able to connect to your cluster via the mongosh command line tool? Did you temporarily allow access to 0.0.0.0/0 which will not block any access for testing? If you are not able to connect when 0.0.0.0/0, then it would seem that you would have a VPN or firewall blocking your access to the Atlas server.

I can verify that the connection gets closed after 30 seconds from my machine, which is what I would expect as my IP address is not in the allow list either explicitly or in a range of allowed IPs. My test was against the old cluster which is still running, because you didn’t give any information about the newly rebuilt one.

1 Like

It did not work with 0.0.0.0/0, but it did work with my iPhone, I used it as a hot spot. As of now I am not connected with a vpn, I guess it could be my router causing it. Because I have the IP address from my router.

MongoServerSelectionError: Server selection timed out after 30000 ms
    at Timeout._onTimeout (/Users/melle/Desktop/crud for demo/node_modules/mongodb/lib/sdam/topology.js:293:38)
    at listOnTimeout (node:internal/timers:559:17)
    at processTimers (node:internal/timers:502:7) {
  reason: TopologyDescription {
    type: 'ReplicaSetNoPrimary',
    servers: Map(3) {
      'ac-jas6yzg-shard-00-02.3anzuip.mongodb.net:27017' => [ServerDescription],
      'ac-jas6yzg-shard-00-01.3anzuip.mongodb.net:27017' => [ServerDescription],
      'ac-jas6yzg-shard-00-00.3anzuip.mongodb.net:27017' => [ServerDescription]
    },
    stale: false,
    compatible: true,
    heartbeatFrequencyMS: 10000,
    localThresholdMS: 15,
    setName: 'atlas-2hvnvb-shard-0',
    maxElectionId: null,
    maxSetVersion: null,
    commonWireVersion: 0,
    logicalSessionTimeoutMinutes: null
  },
  code: undefined,
  [Symbol(errorLabels)]: Set(0) {}
}