How do I find the root cause of this error?
As of now I restart the MongoDB when this error is encountered. It would be great if I can get some pointers to debug this issue. I tried on net but couldn’t solve this issue.
Can multiple user requests going to node at the same time cause this?
ERROR:
MongooseServerSelectionError: connection timed out
at Model.$wrapCallback (/root/cops/node_modules/mongoose/lib/model.js:5078:32)
at /root/cops/node_modules/mongoose/lib/query.js:4510:21
at /root/cops/node_modules/mongoose/lib/helpers/promiseOrCallback.js:32:5
at new Promise (<anonymous>)
at promiseOrCallback (/root/cops/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:10)
at model.Query.exec (/root/cops/node_modules/mongoose/lib/query.js:4509:10)
at Query.then (/root/cops/node_modules/mongoose/lib/query.js:4592:15)
at runNextTicks (node:internal/process/task_queues:60:5)
at process.processImmediate (node:internal/timers:442:9) {
reason: TopologyDescription {
type: 'Single',
setName: null,
maxSetVersion: null,
maxElectionId: null,
servers: Map(1) { '127.0.0.1:27017' => [ServerDescription] },
stale: false,
compatible: true,
compatibilityError: null,
logicalSessionTimeoutMinutes: null,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
commonWireVersion: 6
}
}
my mongo connection code is as follows
const mongooseOpts = {
useUnifiedTopology: true,
useNewUrlParser: true,
useFindAndModify: false,
// autoReconnect: true,
// reconnectTries: Number.MAX_VALUE,
// reconnectInterval: 1000,
poolSize: 10,
};
mongoose.connect('mongodb://127.0.0.1:27017/mca', mongooseOpts)
.then(() => {
console.log('Connected to database @ ' + new Intl.DateTimeFormat('en-IN', { timeStyle: 'medium', dateStyle: 'medium', timeZone: 'Asia/Kolkata' }).format(new Date()));
})
.catch((err) => {
console.log('Database connection failed on ' + new Intl.DateTimeFormat('en-IN', { timeStyle: 'medium', dateStyle: 'medium', timeZone: 'Asia/Kolkata' }).format(new Date()) + ', Err: ' + err);
});