mongo db error of connect ECONNREFUSED ::1:27017

  ERROR:If you find an error during connection to mongodb


MongooseServerSelectionError: connect ECONNREFUSED ::1:27017

    at _handleConnectionErrors (C:\Users\Yash jain\nodejjjs\restfulapi\node_modules\mongoose\lib\connection.js:792:11)

    at NativeConnection.openUri (C:\Users\Yash jain\nodejjjs\restfulapi\node_modules\mongoose\lib\connection.js:767:11)

    at runNextTicks (node:internal/process/task_queues:60:5)

    at listOnTimeout (node:internal/timers:538:9)   

    at process.processTimers (node:internal/timers:512:7) {

  reason: TopologyDescription {

    type: 'Unknown',

    servers: Map(1) { 'localhost:27017' => [ServerDescription] },

    stale: false,

    compatible: true,

    heartbeatFrequencyMS: 10000,

    localThresholdMS: 15,

    setName: null,

    maxElectionId: null,

    maxSetVersion: null,

    commonWireVersion: 0,

    logicalSessionTimeoutMinutes: null

  },

  code: undefined

}

SOLUTION:

If you are using latest nodejs (v17.x) , then try updating mongodb url from localhost to 127.0.0.1

use :mongodb://127.0.0.1:27017

Comments