I got the Error MongooseServerSelectionError: Server selection timed out after 30000 ms
.
I am using MongoDB Atlas.
I've tried changing useUnifiedTopology
to 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?