Can't connect to mongodb on localost using nodejs driver on windows

17 Views Asked by At

I run a local instance of mongodb and connect to it using the nodejs driver. I didn't had any problems to connect until I switched to a replica set:

replication:
   oplogSizeMB: 2000
   replSetName: rs0
   enableMajorityReadConcern: false

When using a client like NoSQLBooster I can connect without any problems. It show me the following connection URLS:

mongodb://localhost:27017 (direct) mongodb://localhost:27017/?replicaSet=rs0

When I'm passing them to await MongoClient.connect(this.config.connectionURL I'm getting:

MongoServerSelectionError: connect ECONNREFUSED ::1:21017
    at Timeout._onTimeout (C:\Projects\cyway\cyway-webapp\api\node_modules\mongodb\src\sdam\topology.ts:567:30)
    at listOnTimeout (node:internal/timers:569:17)
    at processTimers (node:internal/timers:512:7) {
  reason: TopologyDescription {
    type: 'ReplicaSetNoPrimary',
    servers: Map(1) { 'localhost:21017' => [ServerDescription] },
    stale: false,
    compatible: true,
    heartbeatFrequencyMS: 10000,
    localThresholdMS: 15,
    setName: 'rs0',
    maxElectionId: null,
    maxSetVersion: null,
    commonWireVersion: 0,
    logicalSessionTimeoutMinutes: null
  },
  code: undefined,
  [Symbol(errorLabels)]: Set(0) {}
}
0

There are 0 best solutions below