Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-4539

Investigate NODE-4538 - Cannot connect to local mongod

    • Type: Icon: Task Task
    • Resolution: Works as Designed
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None
    • 0
    • Not Needed

      NODE-4538 Description
      I am tearing my hair out with troubles connecting to my local mongodb via the node client. It was working fine and now has explicably stopped connecting at all.
      const { MongoClient } = require('mongodb')

      const uri = "mongodb://localhost:27017"
      const client = new MongoClient(uri, { connectTimeoutMS: 1000 })
      console.log("connecting") // gets here
      client.connect().then(() => { console.log("connected") // doesn't get here }) .catch(e => { console.log("error") // gets here after 30s so below })
       
      -------------------
      error MongoServerSelectionError: connect ECONNREFUSED ::1:27017
      at Timeout._onTimeout (/Users/jonahfox/dublive/test-mongo-connect/node_modules/mongodb/lib/sdam/topology.js:293:38)
      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] }

      ,
      stale: false,
      compatible: true,
      heartbeatFrequencyMS: 10000,
      localThresholdMS: 15,
      logicalSessionTimeoutMinutes: undefined
      },
      code: undefined,
      [Symbol(errorLabels)]: Set(0) {}
      }

       
      I see nothing in the mongod logs about any kind of connection.

      However it does connect from Mongo Compass using the same uri and also from mongo and mongosh.

       

      Env: 

      • mongodb-native-client 4.8.1
      • MacOS Big Sur
      • Node v18.7.0

      Things I have tried to no avail

      • different port
      • various different mongod versions.
      • different node client versions.
      • interestingly it doesn't seem to honour the connectTimeoutMS.
      • deleting and recreating /data/db
      • restarting
      • connecting to Mongo Atlas – which does work!

      What am I doing wrong?

            Assignee:
            bailey.pearson@mongodb.com Bailey Pearson
            Reporter:
            dbeng-pm-bot PM Bot
            Bailey Pearson
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: