Load balancing mongos


I have created a sharded environment with 2 mongos. I am trying to use HAProxy as a load balancer for the mongos. When I try to connect using the loadBalanced=true flag I always get error.

MongoCompatibilityError: Driver attempted to initialize in load balancing mode, but the server does not support this mode.

Maybe I have missed some configurations or is it possible to use the loadBalanced=true flag when using HAProxy as load balancer for the mongos?

are you saying you put 2 mongos behind a HAProxy ?

what’s your connection URI like?

Yes. It is correct.
My connection URI is mongodb://[host]:27017/test?loadBalanced=true

i don’t know how mongodb handles this options, but i got below links. Hope they can help: