mongoose: Connection fail on any Mongoose version over 10.7.12 [Ubuntu 20.04]

Hello. I’m working on a Ubuntu 20.04 machine.

{ useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex: true, useFindAndModify: false, }

These are my connection options.

"mongodb+srv://[CENSOR]:[CENSOR]@maineatcluser.rsb2q.gcp.mongodb.net/destinations?retryWrites=true&w=majority"

and this is my connection URI.

Details of libraries and versions I get Error on :-

"mongodb": "^3.6.2",
"mongoose": "^5.10.11",

Node Version : 14.15.0

Details of Working setup :-

"mongodb": "^3.6.2",
"mongoose": "5.7.12",

Node Version : 14.15.0

I am pretty sure the mongodb version in my package.json probably doesn’t matter but including anyways.

**Please Note that I have 0.0.0.0 whitelisted so this is not an IP Whitelist issue.

Also the problem only persists on this Ubuntu 20.04 Machine. I have a Windows 10 Setup in home [Development environment] Where it’s all okay.**

{ 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://docs.atlas.mongodb.com/security-whitelist/
    at NativeConnection.Connection.openUri (/home/brix/Project_EAT/eat_backend/node_modules/mongoose/lib/connection.js:803:32)
    at cb (/home/brix/Project_EAT/eat_backend/node_modules/mongoose/lib/index.js:342:10)
    at Promise (/home/brix/Project_EAT/eat_backend/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:5)
    at new Promise (<anonymous>)
    at promiseOrCallback (/home/brix/Project_EAT/eat_backend/node_modules/mongoose/lib/helpers/promiseOrCallback.js:30:10)
    at Mongoose.connect (/home/brix/Project_EAT/eat_backend/node_modules/mongoose/lib/index.js:341:10)
    at Object.<anonymous> (/home/brix/Project_EAT/eat_backend/index.js:55:4)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
  message:
   '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://docs.atlas.mongodb.com/security-whitelist/',
  reason:
   TopologyDescription {
     type: 'ReplicaSetNoPrimary',
     setName: null,
     maxSetVersion: null,
     maxElectionId: null,
     servers:
      Map {
        'maineatcluser-shard-00-00.rsb2q.gcp.mongodb.net:27017' => [ServerDescription],
        'maineatcluser-shard-00-01.rsb2q.gcp.mongodb.net:27017' => [ServerDescription],
        'maineatcluser-shard-00-02.rsb2q.gcp.mongodb.net:27017' => [ServerDescription] },
     stale: false,
     compatible: true,
     compatibilityError: null,
     logicalSessionTimeoutMinutes: null,
     heartbeatFrequencyMS: 10000,
     localThresholdMS: 15,
     commonWireVersion: null } }

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 24 (6 by maintainers)

Most upvoted comments

what fixed it was that i re-indexed every database and collections and the error is gone.

Hi @p3x-robot , Could you please provide me a short brief on how I may do that?

https://stackoverflow.com/questions/12187225/command-to-reindex-all-mongodb-collections

db.getCollectionNames().forEach(function(collection){db[collection].reIndex()});