Getting server selection timeout error when maintenance happend on mongodb(mongodb atlas) server
See original GitHub issueHi,
I am using mongoose api to connect to mongodb. When any maintenance happend on mongodb i am getting server selection timeout error on running application.
mongodb - 4.0.17 mongoose - 5.7.6 node - 8.12.0
mongoose connection code -
mongoose.Promise = global.Promise;
mongoose.connection.on('connected', function () {
console.log("MongoDB event connected");
});
mongoose.connection.once('open', function () {
console.log('Connection to mongodb database is open');
});
mongoose.connection.on('disconnected', function () {
console.log("MongoDB event disconnected");
});
mongoose.connection.on('reconnected', function () {
console.log('MongoDB event reconnected');
});
mongoose.connection.on('error', function (err) {
console.log('MongoDB event error: ' + err);
});
mongoUri = 'mongodb+srv://<userid>:<password>@cluster0-OMITTED.mongodb.net/mydb?retryWrites=true&w=majority';
mongoose.connect(mongoUri , {
useUnifiedTopology: true,
useNewUrlParser: true,
useFindAndModify: false, //to remove findAndModify deprication warming
autoIndex: false, //false
reconnectTries: Number.MAX_VALUE,
reconnectInterval: 500, //In milliseconds
poolSize: 80,
socketTimeoutMS: 60000, //Close sockets after 45 seconds of inactivity
}).then(() => {
console.log("Database connected successfully");
}).catch(err => {
console.log('App starting error:' + err.stack);
});
Issue Analytics
- State:
- Created 3 years ago
- Comments:8
Top Results From Across the Web
MongoDB connection error: MongoTimeoutError: Server ...
Please Check your Password, Username OR IP configuration. Mostly "Server selection timed out after 30000 ms at Timeout.
Read more >Server selection error: server selection timeout, current topology
I'm trying to connect to via my code in golang. I am using the mongo-driver module. I am able to connect to instance:...
Read more >Understanding MongoDB Client Timeout Options - ScaleGrid
Server selection timeout is the number of milliseconds the mongo driver will wait to select a server for an operation before giving up...
Read more >Mongoose v6.8.2: Connecting to MongoDB
Buffering; Error Handling; Options; Connection String Options; Connection Events; A note about keepAlive; Server Selection; Replica Set Connections ...
Read more >server selection timed out after 30000 ms - You.com
I got the Error MongooseServerSelectionError: Server selection timed out after 30000 ms. I am using MongoDB Atlas and tried to add the IP...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I can confirm that v5.9.10 no longer fails.
I reproduced it with mongo atlas M10 cluster first with mongoose v5.8.11 and got the
NotMaster
error 3 min after i used the Restart primary button to test failover on Atlas. I ran the test again using 5.9.10 and the failover ended without interrupting writes. My test script was constantly writing to db.If you’re experiencing a similar issue, please open a new issue and follow the issue template.