-
Type: Question
-
Resolution: Works as Designed
-
Priority: Minor - P4
-
None
-
Affects Version/s: 4.8.1
-
Component/s: None
-
Empty show more show less
-
Not Needed
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)
,
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?
- depends on
-
NODE-4539 Investigate NODE-4538 - Cannot connect to local mongod
- Closed