MongoServerSelectionError: connect ECONNREFUSED ::1:27017 2nd February 2024

Hello all,
Am new to mongodb, am frustrated by this connection in all my 3pcs it only connects in one pc.
I have search for solution on internet to replace on localhost:27017 with 127.0.0.1:27017 or with 0.0.0.0:27017
I have installed latest mongodb 7.0.5 and shell and compass
am get no results Below is the code am just want to see “Great Connection” on terminal:

const MongoClient = require('mongodb').MongoClient

MongoClient.connect('mongodb://127.0.0.1:27017', (err, db) => {
  if (err) throw err

  console.log("Great Connection");
  //   db.collection('mammals').find().toArray((err, result) => {
  //     if (err) throw err
  
  //     console.log(result)
  //   })

})

*** Running the code returns the following error:**

C:\Users\Graphics07\Desktop\node\node_modules\mongodb\lib\sdam\topology.js:276                                                                                      
            const timeoutError = new error_1.MongoServerSelectionError(`Server selection timed out after ${options.serverSelectionTimeoutMS} ms`, this.description);
                                 ^                                                                                                                                  

MongoServerSelectionError: connect ECONNREFUSED ::1:27017
    at EventTarget.<anonymous> (C:\Users\Graphics07\Desktop\node\node_modules\mongodb\lib\sdam\topology.js:276:34)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:731:20)
    at EventTarget.dispatchEvent (node:internal/event_target:673:26)
    at abortSignal (node:internal/abort_controller:308:10)
    at TimeoutController.abort (node:internal/abort_controller:338:5)
    at Timeout.<anonymous> (C:\Users\Graphics07\Desktop\node\node_modules\mongodb\lib\utils.js:1011:92)
    at listOnTimeout (node:internal/timers:564:17)
    at process.processTimers (node:internal/timers:507:7) {
  reason: TopologyDescription {
    type: 'Unknown',
    servers: Map(1) {
      'localhost:27017' => ServerDescription {
        address: 'localhost:27017',
        type: 'Unknown',
        hosts: [],
        passives: [],
        arbiters: [],
        tags: {},
        minWireVersion: 0,
        maxWireVersion: 0,
        roundTripTime: -1,
        lastUpdateTime: 856379,
        lastWriteDate: 0,
        error: MongoNetworkError: connect ECONNREFUSED ::1:27017
            at connectionFailureError (C:\Users\Graphics07\Desktop\node\node_modules\mongodb\lib\cmap\connect.js:379:20)
            at Socket.<anonymous> (C:\Users\Graphics07\Desktop\node\node_modules\mongodb\lib\cmap\connect.js:285:22)
            at Object.onceWrapper (node:events:628:26)
            at Socket.emit (node:events:513: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) {
          [Symbol(errorLabels)]: Set(1) { 'ResetPool' },
          [cause]: Error: connect ECONNREFUSED ::1:27017
              at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1300:16) {
            errno: -4078,
            code: 'ECONNREFUSED',
            syscall: 'connect',
            address: '::1',
            port: 27017
          }
        },
        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
      address: '::1',
      port: 27017
    }
  }
}

Node.js v18.12.1
[nodemon] app crashed - waiting for file changes before starting...

Hey @zig_lar,

Welcome to the MongoDB Community :sparkles:

Could you please confirm that MongoDB is running successfully and that you can connect to it using mongosh or MongoDB Compass? If not, please refer to Install MongoDB Community Edition and follow the steps to install MongoDB on your PC for your specific OS.

As I can see the error message, indicates that there is no mongod running at the given address. I believe you need to start mongod first. For more information, please refer to the mongod - MongoDB documentation.

I hope it helps. In case the issue persists, please feel free to reach out with the workflow details you followed so the community can assist you better.

Best regards,
Kushagra