I am facing an issue when trying to connect to my MongoDB Atlas cluster from networks other than my home network. The error I receive is as follows:

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://www.mongodb.com/docs/atlas/security-whitelist/
[nodemon] 3.1.0
[nodemon] to restart at any time, enter rs
[nodemon] watching path(s): .
[nodemon] watching extensions: ts,json
[nodemon] starting ts-node src/index.ts
Server is running at port 3000
Connected to mongodb.
[nodemon] restarting due to changes…
[nodemon] starting ts-node src/index.ts
Server is running at port 3000
C:\Users\gonza\OneDrive\Escritorio\Respaldo\login192Completo\BackenIncidencia\node_modules\mongoose\lib\connection.js:896
err = new ServerSelectionError();
^
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://www.mongodb.com/docs/atlas/security-whitelist/
at _handleConnectionErrors (C:\Users\gonza\OneDrive\Escritorio\Respaldo\login192Completo\BackenIncidencia\node_modules\mongoose\lib\connection.js:896:11)
at NativeConnection.openUri (C:\Users\gonza\OneDrive\Escritorio\Respaldo\login192Completo\BackenIncidencia\node_modules\mongoose\lib\connection.js:847:11) {
reason: TopologyDescription {
type: ‘ReplicaSetNoPrimary’,
servers: Map(3) {
ac-r6awj9d-shard-00-00.ndaks7f.mongodb.net:27017’ => [ServerDescription],
ac-r6awj9d-shard-00-01.ndaks7f.mongodb.net:27017’ => [ServerDescription],
ac-r6awj9d-shard-00-02.ndaks7f.mongodb.net:27017’ => [ServerDescription]
},
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
setName: ‘atlas-zruwn9-shard-0’,
maxElectionId: null,
maxSetVersion: null,
commonWireVersion: 0,
logicalSessionTimeoutMinutes: null
},
code: undefined
}

What I Have Tried:

  1. Whitelisting IP: I have ensured that the IP from which I am trying to connect is in the MongoDB Atlas IP whitelist.
  2. Configuration Check: I have checked my connection configuration, and it seems correct.
  3. Home Network Access: I can successfully connect from my home network but not from other networks
1 Like

i also face same issue, how to resolve this