title: Should I use hostname or IP address for mongodb connection string
body: <p>I've set up a MongoDB replica set with 3 nodes. All servers live in the same VPC, but in different availability zones. Thanks to <code>etc/hosts</code> file, in while I describe where to find the other nodes, my replica set is able to communicate between nodes. My <code>etc/hosts</code> file looks like this on all 3 nodes.</p>
  
  <pre><code>127.0.0.1 localhost mongo0.example.com
  Private IP 1 mongo0.example.com
  Private IP 2 mongo1.example.com
  Private IP 3 mongo2.example.com
  </code></pre>
  
  <p>Now, the app server needs to connect to the replica set. Should I use the IP addresses of the nodes in the connection string or should I use the hostnames? </p>
  
  <p><code>mongodb://private_ip1:27017,private_ip2:27017,private_ip3:27017/dbname?replicaSet=rs0</code>
  or
  <code>mongodb://mongo0.example.com:27017,mongo1.example.com:27017,mongo2.example.com:27017/dbname?replicaSet=rs0</code></p>
  
  <p>If it's the latter (hostnames), should I configure the app server's <code>/etc/hosts</code> like each of the mongo nodes? </p>