title: Mongoose Failing to connect to MongoDB replicaSet
body: <p>I have a replicaSet running in k8s, while trying to connect to the replicaSet from nodejs using mongoose, the connection fails with this logs:</p>
  <pre><code>MongooseServerSelectionError: connection timed out                                                                                                                              
      at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:807:32)                                                                                
      at /app/node_modules/mongoose/lib/index.js:340:10                                                                                                                           
      at promiseOrCallback (/app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:10:12)                                                                                    
      at Mongoose._promiseOrCallback (/app/node_modules/mongoose/lib/index.js:1140:10)                                                                                            
      at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:339:20)                                                                                                        
      at /app/src/connect.ts:21:14                                                                                                                                                
      at Promise._execute (/app/node_modules/bluebird/js/release/debuggability.js:313:9)                                                                                          
      at Promise._resolveFromExecutor (/app/node_modules/bluebird/js/release/promise.js:488:18)                                                                                   
      at new Promise (/app/node_modules/bluebird/js/release/promise.js:79:10)                                                                                                     
      at connect (/app/src/connect.ts:20:10)                                                                                                                                      
      at initialiseDatabase (/app/src/connect.ts:8:5)                                                                                                                             
      at Object.&lt;anonymous&gt; (/app/src/mongoose.ts:36:19)                                                                                                                          
      at Module._compile (internal/modules/cjs/loader.js:1085:14)                                                                                                                 
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)                                                                                                   
      at Module.load (internal/modules/cjs/loader.js:950:32)                                                                                                                      
      at Function.Module._load (internal/modules/cjs/loader.js:790:12)
      at Module.require (internal/modules/cjs/loader.js:974:19)
      at require (internal/modules/cjs/helpers.js:101:18)
      at Object.&lt;anonymous&gt; (/app/src/user/operations/find-by-id.ts:1:1)
      at Module._compile (internal/modules/cjs/loader.js:1085:14)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
      at Module.load (internal/modules/cjs/loader.js:950:32)
      at Function.Module._load (internal/modules/cjs/loader.js:790:12)
      at Module.require (internal/modules/cjs/loader.js:974:19)
      at require (internal/modules/cjs/helpers.js:101:18)
      at Object.&lt;anonymous&gt; (/app/src/middleware/authenticate.ts:7:1)
      at Module._compile (internal/modules/cjs/loader.js:1085:14)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
      at Module.load (internal/modules/cjs/loader.js:950:32)
      at Function.Module._load (internal/modules/cjs/loader.js:790:12)
      at Module.require (internal/modules/cjs/loader.js:974:19)
      at require (internal/modules/cjs/helpers.js:101:18)
      at Object.&lt;anonymous&gt; (/app/src/app.ts:8:1)
      at Module._compile (internal/modules/cjs/loader.js:1085:14)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
      at Module.load (internal/modules/cjs/loader.js:950:32)
      at Function.Module._load (internal/modules/cjs/loader.js:790:12)
      at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12)
      at internal/main/run_main_module.js:17:47 {
    reason: TopologyDescription {
      type: 'ReplicaSetNoPrimary',
      servers: Map(3) {
        'mongodb-0.mongodb-headless.staging.svc.cluster.local:27017' =&gt; [ServerDescription],
        'mongodb-1.mongodb-headless.staging.svc.cluster.local:27017' =&gt; [ServerDescription],
        'mongodb-2.mongodb-headless.staging.svc.cluster.local:27017' =&gt; [ServerDescription]
      },
  </code></pre>
  <p>And this is my connection string:</p>
  <pre><code>mongodb://username:pw@mongodb-0.mongodb-headless.staging.svc.cluster.local:27017,mongodb-1.mongodb-headless.staging.svc.cluster.local:27017,mongodb-2.mongodb-headless.staging.svc.cluster.local:27017/labxpert?authSource=admin&amp;serverSelectionTimeoutMS=50000&amp;replicaSet=rs0
  </code></pre>
  <p>When I test the connection with the mongo Shell, it works just fine.</p>
  <p>What could be causing the <code>MongooseServerSelectionError: connection timed out</code>.</p>