skip to Main Content

I have created my mongoDb database in mongoDb Atlas and was trying to connect to server(node.js). But I’m unable to connect to my database.ERR_SOCKET_CONNECTION_TIMEOUT error is showing in the server log. Plaese find the error log below.

return new error_1.MongoNetworkError(err);
                   ^

MongoNetworkError: Socket connection timeout
    at connectionFailureError (D:MERNProjectsocial-media-apinode_modulesmongodblibcmapconnect.js:370:20)
    at TLSSocket.<anonymous> (D:MERNProjectsocial-media-apinode_modulesmongodblibcmapconnect.js:293:22)
    at Object.onceWrapper (node:events:626:26)
    at TLSSocket.emit (node:events:511:28)
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  cause: Error [ERR_SOCKET_CONNECTION_TIMEOUT]: Socket connection timeout
      at new NodeError (node:internal/errors:399:5)
      at internalConnectMultiple (node:net:1099:20)
      at Timeout.internalConnectMultipleTimeout (node:net:1638:3)
      at listOnTimeout (node:internal/timers:575:11)
      at process.processTimers (node:internal/timers:514:7) {
    code: 'ERR_SOCKET_CONNECTION_TIMEOUT'
  },
  connectionGeneration: 18,
  [Symbol(errorLabels)]: Set(1) { 'ResetPool' }
}

Node.js v20.1.0
[nodemon] app crashed - waiting for file changes before starting...

MONGODB_URL = "mongodb+srv://<username here>:<password here>@clustername.bwmogva.mongodb.net/<database name>?retryWrites=true&w=majority"

I have tried below options :

useNewUrlParser : true, socketTimeoutMS : 3000,

Also tried socketTimeout to 30000. Checked the network settings in Atlas. Gave network access for all network. Still getting the same error. I’m able to connect to database via MongoDB compass. It would be great if anyone can help me rectify the problem.

2

Answers


  1. Chosen as BEST ANSWER

    Issue solved! I think it was a bug in node version. I have updated node version to v20.7.0. I was using an older version.


  2. I also faced the same problem but after updating to latest node version the problem is solved

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search