1

I got the Error MongooseServerSelectionError: Server selection timed out after 30000 ms. I am using MongoDB Atlas. I've tried changing useUnifiedTopologyto false and my application doesn't crash, but I get the Error DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.

The whole error message:

MongooseServerSelectionError: Server selection timed out after 30000 ms
 {
  reason: TopologyDescription {
    type: 'ReplicaSetWithPrimary',
    setName: 'atlas-lhb3t7-shard-0',
    maxSetVersion: 1,
    maxElectionId: 7fffffff0000000000000005,
    servers: Map {
      'wolfgangtest-shard-00-02.q8jpm.mongodb.net:27017' => [ServerDescription],
      'wolfgangtest-shard-00-00.q8jpm.mongodb.net:27017' => [ServerDescription],
      'wolfgangtest-shard-00-01.q8jpm.mongodb.net:27017' => [ServerDescription]
    },
    stale: false,
    compatible: true,
    compatibilityError: null,
    logicalSessionTimeoutMinutes: null,
    heartbeatFrequencyMS: 10000,
    localThresholdMS: 15,
    commonWireVersion: 8
  }
}

My Mongoose code:

const dbOptions = {
            useNewUrlParser: true,
            autoIndex: false,
            poolSize: 5,
            connectTimeoutMS: 10000,
            family: 4,
            useUnifiedTopology: true
        };
        
        mongoose.connect('mongodb+srv://Wolfgang:christian13561z@wolfgangtest.q8jpm.mongodb.net/Wolfgang?retryWrites=true&w=majority', dbOptions);
        mongoose.set('useFindAndModify', false);
        mongoose.Promise = global.Promise;

How do i fix / bypass this?

HoppelHobbit
  • 36
  • 1
  • 5

1 Answers1

-1

I think that there is a problem with your the connection URL from my experience with this kind of eror.Try Try to use the same connecton URL in MongoDB compass if you use windows or robomongo.

You can also try to check :

MongoDB connection error: MongoTimeoutError: Server selection timed out after 30000 ms

MongoTimeoutError: Server selection timed out after 30000 ms while connecting to mongoDB

Server selection timed out after 10000 ms - Cannot connect Compass to mongoDB on localhost

Christian LSANGOLA
  • 2,947
  • 4
  • 22
  • 36