Connecting to MongoDB Replica Set behind a Load Balancer <p>I am a little confused on how MongoDB handles replica sets. I have the following setup:</p> <ul> <li>2 Replica set members to store data</li> <li>1 Arbiter</li> <li>Everything is in a Virtual Network</li> </ul> <p>There are two scenarios:</p> <p><strong>Scenario 1</strong></p> <ul> <li>No Load balancer. </li> <li>DataVM0 is accessible at public IP 123.123.12.1</li> <li>DataVM1 is accessible at public IP 123.123.12.2</li> <li>ArbiterVM is accessible public at IP 123.123.12.3</li> </ul> <p>Here, my connection string would look something like:</p> <pre><code>mongodb://123.123.12.1:27017,123.123.12.2:27017,123.123.12.3:27017/?replicaSet=samplereplicaset </code></pre> <p><strong>Scenario 2</strong></p> <ul> <li>Load balancer accessible at public IP 123.123.12.1. </li> <li>DataVM0 is not publicly accessible.</li> <li>DataVM1 is not publicly accessible.</li> <li>ArbiterVM is not publicly accessible.</li> <li>LoadBalancer port 27017 is forwarded to DataVM0 port 27017</li> <li>LoadBalancer port 27018 is forwarded to DataVM1 port 27017</li> <li>LoadBalancer port 27019 is forwarded to ArbiterVM port 27017</li> </ul> <p>Here, my connection string would look something like this:</p> <pre><code>mongodb://123.123.12.1:27017,123.123.12.1:27018,123.123.12.1:27019/?replicaSet=samplereplicaset </code></pre> <hr> <p>Are both these ways to connect equivalent in terms of replica sets? I ask this since in the connection string, I'm not directly connecting to any of the VMs.</p> <p>All VMs are accessible from every other VM in the virtual network. DNS and everything works properly.</p>