title: MongooseError [MongooseServerSelectionError]: connection <monitor> to 52.6.250.237:27017 closed
body: <p>I am trying to save data in mongodb through post method and using mongodb atlas with node.js but it keeps giving me an error, I provided correct connection string and correct password. Please help in regarding this issue. Thanks.</p>
  <p>Here is the code:</p>
  <pre><code>const mongoose = require('mongoose');
  
  const monngodb_url=&quot;mongodb+srv://maarij:asdf360@cluster0-j7wis.mongodb.net/authDB?retryWrites=true&amp;w=majority&quot;;
  
  mongoose.connect(monngodb_url, {useNewUrlParser: true,useUnifiedTopology: true}).then(()=&gt;{
      console.log(&quot;mongodb is connected&quot;);
  }).catch((error)=&gt;{
      console.log(&quot;mondb not connected&quot;);
      console.log(error);
  });
  </code></pre>
  <p>Here is the error:</p>
  <pre><code>server is running on port 3000
  { name: 'myName', email: 'e@mail.com', password: 'abcdefg' }
  mondb not connected
  MongooseError [MongooseServerSelectionError]: connection &lt;monitor&gt; to 52.6.250.237:27017 closed
      at new MongooseServerSelectionError (D:\react-native\reactNativeBackend\node_modules\mongoose\lib\error\serverSelection.js:22:11)
      at NativeConnection.Connection.openUri (D:\react-native\reactNativeBackend\node_modules\mongoose\lib\connection.js:808:32)
      at Mongoose.connect (D:\react-native\reactNativeBackend\node_modules\mongoose\lib\index.js:333:15)
      at Object.&lt;anonymous&gt; (D:\react-native\reactNativeBackend\db\db.js:5:10)
      at Module._compile (internal/modules/cjs/loader.js:955:30)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
      at Module.load (internal/modules/cjs/loader.js:811:32)
      at Function.Module._load (internal/modules/cjs/loader.js:723:14)
      at Module.require (internal/modules/cjs/loader.js:848:19)
      at require (internal/modules/cjs/helpers.js:74:18)
      at Object.&lt;anonymous&gt; (D:\react-native\reactNativeBackend\index.js:4:19)
      at Module._compile (internal/modules/cjs/loader.js:955:30)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
      at Module.load (internal/modules/cjs/loader.js:811:32)
      at Function.Module._load (internal/modules/cjs/loader.js:723:14)
      at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10) {
    message: 'connection &lt;monitor&gt; to 52.6.250.237:27017 closed',
    name: 'MongooseServerSelectionError',
    reason: TopologyDescription {
      type: 'ReplicaSetNoPrimary',
      setName: null,
      maxSetVersion: null,
      maxElectionId: null,
      servers: Map {
        'cluster0-shard-00-01-j7wis.mongodb.net:27017' =&gt; [ServerDescription],
        'cluster0-shard-00-02-j7wis.mongodb.net:27017' =&gt; [ServerDescription],
        'cluster0-shard-00-00-j7wis.mongodb.net:27017' =&gt; [ServerDescription]
      },
      stale: false,
      compatible: true,
      compatibilityError: null,
      logicalSessionTimeoutMinutes: null,
      heartbeatFrequencyMS: 10000,
      localThresholdMS: 15,
      commonWireVersion: null
    },
    [Symbol(mongoErrorContextSymbol)]: {}
  }
  </code></pre>