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 (/opt/render/project/src/node_modules/mongoose/lib/connection.js:829:11)
    at NativeConnection.openUri (/opt/render/project/src/node_modules/mongoose/lib/connection.js:804:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async connectDB (/opt/render/project/src/config/database.js:5:18) {
  reason: TopologyDescription {
    type: 'ReplicaSetNoPrimary',
    servers: Map(3) {
      'ac-mwbqrb7-shard-00-00.ysfsjei.mongodb.net:27017' => [ServerDescription],
      'ac-mwbqrb7-shard-00-01.ysfsjei.mongodb.net:27017' => [ServerDescription],
      'ac-mwbqrb7-shard-00-02.ysfsjei.mongodb.net:27017' => [ServerDescription]
    },
    stale: false,
    compatible: true,
    heartbeatFrequencyMS: 10000,
    localThresholdMS: 15,
    setName: 'atlas-oquqci-shard-0',
    maxElectionId: null,
    maxSetVersion: null,
    commonWireVersion: 0,
    logicalSessionTimeoutMinutes: null
  },
  code: undefined
1

There are 1 best solutions below

0
Dat Huynh On BEST ANSWER

enter image description here

When you create new cluster, Mongo Atlas will add your IP into whitelist. So your machine can connect to it. If you want any machine can access to your Mongo Atlas, you can set 0.0.0.0/0 into whitelist (as picture attachment).