Mongo DB buffering time out after 10000ms

Can you start with a simple troubleshooting script? Something like the following:

const mongoose = require('mongoose');

mongoose.connect('your_mongodb_uri', { useNewUrlParser: true, useUnifiedTopology: true })
  .then(() => console.log('Connected to MongoDB'))
  .catch(err => console.error('Could not connect to MongoDB', err));

Also - you can play with the timeout settings on your connection like this:

mongoose.connect('your_mongodb_uri', { useNewUrlParser: true, useUnifiedTopology: true, serverSelectionTimeoutMS: 30000, // 30 seconds socketTimeoutMS: 45000, // 45 seconds });

The last thing I would suggest is to incorporate more verbose error messages… console.logs… like this:

mongoose.connection.on('connected', () => {
  console.log('Mongoose connected to MongoDB');
  // Your database operations here
});

mongoose.connection.on('error', err => {
  console.error('Mongoose connection error:', err);
});

Let us know if this helps.

1 Like