Does go mongodb driver code determine primary based on given hostnames?

I have 3 existing mongo instances serving an existing kubernetes cluster, and added 3 new instances to the replica set while setting up a new kubernetes cluster. The goal is to switch to the 3 new instances and tear down the 3 old instances when I remove my old k8s cluster. codebase is golang, so using the Go Mongo driver. In a new cluster, I have mongo hostnames set to only the new instances I created. From my testing, it seems like the Go Mongo driver programmatically determines the primary node even though I don’t have the primary node in the hostnames list in my new kubernetes cluster and writes go through fine. can someone point me to where in the codebase it does this? I assume it determines the primary node given a hostname and directs writes to the primary node.

Thank you!

Hi @Arun_Srinivasan and welcome in the MongoDB Community :muscle: !

I can’t find exactly where this is implemented in the Go Driver, but at least I can explain that all the MongoDB driver are implementing the same specs which are in this repo and in this spec, probably around here, it says that Mongo clients are “replica set aware” (or something like that) and that your client is doing “server discovery”.

That basically means that, constantly, the client checks the topology of your cluster and can discover all the nodes, even if they are not in the seed list you initially provided.

It’s always a good practice to provide the entire list of servers in your seed list. But as long as at least one of them is available, your client should be able to ask that node for its configuration and discover the rest.

I hope this helps.



This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.