I keep receiving a log saying that “MongoDB (through mongoose) disconnected” and connects again after 20 seconds, I receive this error at least 1 or 2 times per day. What can be the problem ?
I have a node js running connecting to MongoDB.
Node, Mongoose and MongoDB version:
“node”: “20.17.0”
“mongodb”: “^6.9.0”,
“mongoose”: “^8.7.1”,
Running on a mongodb M0 shared atlas cluster
const db = mongoose.createConnection(process.env.MONGODB_URL);
db.on('error', (error) => {
logger.error('MongoDB (through mongoose) connection error:', error);
});
db.on('disconnected', (error) => {
logger.error('MongoDB (through mongoose) disconnected', error);
});
db.on('connected', () => {
logger.info(null, 'Connected to MongoDB (through mongoose)');
});