0

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) {}
}
MarcS82
  • 2,065
  • 7
  • 29
  • 46
  • Yes, thanks a lot! For me it is not clear why other clients where able to connect using `localhost` and also why this only fails when I use a replica set. – MarcS82 Jul 28 '23 at 12:22
  • I'm no expert, but it seems to depend on how the OS translates `localhost` to an IP address. – rickhg12hs Jul 28 '23 at 12:41

0 Answers0