Hi everyone,
I am working on a Node.js application that connects to MongoDB Atlas, and I’ve encountered a frustrating issue. The server initially connects to the MongoDB database successfully, but after a minute or so, the server disconnects and throws the following error:
MongoServerSelectionError: getaddrinfo EAI_AGAIN undefined
at Timeout._onTimeout (/path/to/project/node_modules/mongodb/lib/sdam/topology.js:292:38)
at listOnTimeout (node:internal/timers:581:17)
at process.processTimers (node:internal/timers:519:7) {
reason: TopologyDescription {
type: ‘Unknown’,
servers: Map(1) {
‘undefined:27017’ => ServerDescription {
address: ‘undefined:27017’,
type: ‘Unknown’,
hosts: ,
passives: ,
arbiters: ,
tags: {},
minWireVersion: 0,
maxWireVersion: 0,
roundTripTime: -1,
lastUpdateTime: 4872501,
lastWriteDate: 0,
error: MongoNetworkError: getaddrinfo EAI_AGAIN undefined
at connectionFailureError (/path/to/project/node_modules/mongodb/lib/cmap/connect.js:387:20)
at Socket. (/path/to/project/node_modules/mongodb/lib/cmap/connect.js:310:22)
at Object.onceWrapper (node:events:634:26)
at Socket.emit (node:events:519:28)
at emitErrorNT (node:internal/streams/destroy:169:8)
at emitErrorCloseNT (node:internal/streams/destroy:128:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
cause: Error: getaddrinfo EAI_AGAIN undefined
at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:120:26) {
errno: -3001,
code: ‘EAI_AGAIN’,
syscall: ‘getaddrinfo’,
hostname: ‘undefined’
},
[Symbol(errorLabels)]: Set(1) { ‘ResetPool’ }
},
topologyVersion: null,
setName: null,
setVersion: null,
electionId: null,
logicalSessionTimeoutMinutes: null,
primary: null,
me: null,
‘$clusterTime’: null
}
},
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
setName: null,
maxElectionId: null,
maxSetVersion: null,
commonWireVersion: 0,
logicalSessionTimeoutMinutes: null
},
code: undefined,
[Symbol(errorLabels)]: Set(0) {}
}
Error complete
MONGODB_URI = mongodb+srv://:@cluster0.bprh4.mongodb.net/
I am using mongodb in cloud