0

I tried to use MongoDB change streams and i need to use replicaSets but mongoDB doesn't let me use it because of load balancer i tried to set it false like this:

mongodb+srv://${process.env.DB_USERNAME}:${process.env.DB_PASSWORD}@${process.env.DB_CLUSTER}/?replicaSet=rs0&loadBalanced=false&readPreference=secondaryPreferred

but its still giving me same error :

MongoParseError: loadBalanced option not supported with a replicaSet option

Here is my connection code:

const uri = `mongodb+srv://${process.env.DB_USERNAME}:${process.env.DB_PASSWORD}@${process.env.DB_CLUSTER}/?replicaSet=rs0&loadBalanced=false&readPreference=secondaryPreferred`;
    const client = new MongoClient(uri, {
      useNewUrlParser: true,
      useUnifiedTopology: true,
    });

    await client.connect();
barankibar
  • 56
  • 1
  • 13

1 Answers1

0

I assume that when you don't configure loadBalanced at all, you see the same exception. If so, the reason for it is that your server has loadBalanced option configured in txt records. When a driver gets these records after resolving SRV, it implicitly adds them to connection string. IE server/driver expects working in load balancing mode which doesn't support replica set option. nslookup should help with checking it. I'm not 100% sure, but I think something like this: nslookup -q=TXT yoururl.com should help to see it

dododo
  • 3,872
  • 1
  • 14
  • 37