title: Can't connect to mongodb with node.js due to mongoServerSelectionError
body: <p>When I try to connect mongodb with node I get this error.(In picture)
  In many tutorial I have seen the solution of the problem can be found by whitelisting the ip address. but trust me I did but nothing happened.
  This is my code</p>
  <pre><code>       const { MongoClient, ServerApiVersion } = require(&quot;mongodb&quot;);
  // async function listDatabases(client){
  //     databasesList = await client.db().admin().listDatabases();
  
  //     console.log(&quot;Databases:&quot;);
  //     databasesList.databases.forEach(db =&gt; console.log(` - ${db.name}`));
  // };
  async function main() {
    /**
     * Connection URI. Update &lt;username&gt;, &lt;password&gt;, and &lt;your-cluster-url&gt; to reflect your cluster.
     * See https://docs.mongodb.com/ecosystem/drivers/node/ for more details
     */
    const uri =
      &quot;mongodb+srv://bran:R8VP2F3ZvEZWRi5l@cluster0.hd6phlm.mongodb.net/?retryWrites=true&amp;w=majority&quot;;
  
    const client = new MongoClient(uri, {
      useNewUrlParser: true,
      useUnifiedTopology: true,
    });
  
    try {
      // Connect to the MongoDB cluster
      await client.connect();
  
      // Make the appropriate DB calls
      await listDatabases(client);
    } catch (e) {
      console.error(&quot;the error: &quot;, e);
    } finally {
      await client.close();
    }
  }
  
  main().catch(console.error);
  async function listDatabases(client) {
    databasesList = await client.db().admin().listDatabases();
  
    console.log(&quot;Databases:&quot;);
    databasesList.databases.forEach((db) =&gt; console.log(` - ${db.name}`));
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/42uRF.png" rel="nofollow noreferrer">This is my code</a></p>
  <p>This is the error I am getting:
  MongoServerSelectionError: connect ETIMEDOUT 15.206.14.158:27017
  at Timeout._onTimeout (E:\node-mongo-connect\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-mg9lmct-shard-00-00.hd6phlm.mongodb.net:27017' =&gt; [ServerDescription],
  'ac-mg9lmct-shard-00-01.hd6phlm.mongodb.net:27017' =&gt; [ServerDescription],
  'ac-mg9lmct-shard-00-02.hd6phlm.mongodb.net:27017' =&gt; [ServerDescription]
  },
  stale: false,
  compatible: true,
  heartbeatFrequencyMS: 10000,
  localThresholdMS: 15,
  setName: 'atlas-hltwao-shard-0',
  maxElectionId: null,
  maxSetVersion: null,
  commonWireVersion: 0,
  logicalSessionTimeoutMinutes: null
  },
  code: undefined,
  [Symbol(errorLabels)]: Set(0) {}
  }</p>
  <p><a href="https://i.stack.imgur.com/cSCJX.png" rel="nofollow noreferrer">This is the error I am getting</a></p>