1

Hi I am in arch based garuda linux and I am facing MongooseServerSelectionError: connect ECONNREFUSED ::1:27017 error while connecting my node app to mongodb.

The error is

MongooseServerSelectionError: connect ECONNREFUSED ::1:27017
    at NativeConnection.Connection.openUri (/home/linux/Desktop/mongo tutorial/node_modules/mongoose/lib/connection.js:797:32)
    at /home/linux/Desktop/mongo tutorial/node_modules/mongoose/lib/index.js:341:10
    at /home/linux/Desktop/mongo tutorial/node_modules/mongoose/lib/helpers/promiseOrCallback.js:32:5
    at new Promise (<anonymous>)
    at promiseOrCallback (/home/linux/Desktop/mongo tutorial/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:10)
    at Mongoose._promiseOrCallback (/home/linux/Desktop/mongo tutorial/node_modules/mongoose/lib/index.js:1167:10)
    at Mongoose.connect (/home/linux/Desktop/mongo tutorial/node_modules/mongoose/lib/index.js:340:20)
    at Object.<anonymous> (/home/linux/Desktop/mongo tutorial/index.js:2:10)
    at Module._compile (node:internal/modules/cjs/loader:1097:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1149:10) {   reason: TopologyDescription {
    type: 'Unknown',
    servers: Map(1) {
      'localhost:27017' => ServerDescription {
        _hostAddress: HostAddress { isIPv6: false, host: 'localhost', port: 27017 },
        address: 'localhost:27017',
        type: 'Unknown',
        hosts: [],
        passives: [],
        arbiters: [],
        tags: {},
        minWireVersion: 0,
        maxWireVersion: 0,
        roundTripTime: -1,
        lastUpdateTime: 19125836,
        lastWriteDate: 0,
        error: MongoNetworkError: connect ECONNREFUSED ::1:27017
            at connectionFailureError (/home/linux/Desktop/mongo tutorial/node_modules/mongodb/lib/cmap/connect.js:293:20)
            at Socket.<anonymous> (/home/linux/Desktop/mongo tutorial/node_modules/mongodb/lib/cmap/connect.js:267:22)
            at Object.onceWrapper (node:events:510:26)
            at Socket.emit (node:events:390:28)
            at emitErrorNT (node:internal/streams/destroy:164:8)
            at emitErrorCloseNT (node:internal/streams/destroy:129:3)
            at processTicksAndRejections (node:internal/process/task_queues:83:21)
      }
    },
    stale: false,
    compatible: true,
    heartbeatFrequencyMS: 10000,
    localThresholdMS: 15,
    logicalSessionTimeoutMinutes: undefined   } }

Node.js v17.3.0

My mongodb compass screenschot enter image description here

Rosan Paudel
  • 120
  • 1
  • 2
  • 10
  • Does this answer your question? [MongooseServerSelectionError: connect ECONNREFUSED ::1:27017](https://stackoverflow.com/questions/69840504/mongooseserverselectionerror-connect-econnrefused-127017) – Joe Jan 18 '22 at 07:35
  • @Joe No but I have found out the solution. And I have answered that also. – Rosan Paudel Jan 18 '22 at 09:06
  • 2
    So this one instead: https://stackoverflow.com/questions/70446871/mongoserverselectionerror-connect-econnrefused-127017 – Joe Jan 18 '22 at 15:36
  • Yep. that's it. – Rosan Paudel Jan 19 '22 at 02:28

2 Answers2

1

This is working on win 10.

mongoose.connect("mongodb://0.0.0.0/test-db");

  • 1
    Your answer does not specifically address the OP's issue. This issue regarding: error: MongoNetworkError: connect ECONNREFUSED ::1:27017, has already been answered at length at StackOverflow. https://stackoverflow.com/questions/70446871/mongoserverselectionerror-connect-econnrefused-127017 – Gray Dec 19 '22 at 23:10
0

The problem was not with the code it was the version. Instead of using

mongoose.connect("mongodb://localhost/test")

I used

mongoose.connect("mongodb://127.0.0.1/test")

it worked.

reference: https://www.mongodb.com/community/forums/t/mongooseserverselectionerror-connect-econnrefused-127-0-0-1-27017/123421

Rosan Paudel
  • 120
  • 1
  • 2
  • 10
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 18 '22 at 09:56