title: mongodb connection string uri not working in the Kubernetes
body: <p>I have deployed mongodb as a StatefulSets on the K8S. It is not connecting, when I try to connect the DB using connection string URI(Ex: mongodb://mongo-0.mongo:27017,mongo-1.mongo:27017/cool_db), but it is connecting and getting the results when I use Endpoint IP Address. </p>
  
  <pre><code># kubectl get sts
  NAME    READY   AGE
  mongo   2/2     7h33m
  
  #kubectl get pods
  NAME                                      READY   STATUS    RESTARTS   AGE
  mongo-0                                   2/2     Running   0          7h48m
  mongo-1                                   2/2     Running   2          7h47m
  
  # kubectl get svc
  NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)     AGE
  kubernetes   ClusterIP   10.96.0.1    &lt;none&gt;        443/TCP     10h
  mongo        ClusterIP   None         &lt;none&gt;        27017/TCP   7h48m
  
  </code></pre>
  
  <p>I'm trying to test the connection using connection string URI in the python using the below process but it fails. </p>
  
  <pre><code>&gt;&gt;&gt; import pymongo
  &gt;&gt;&gt; client = pymongo.MongoClient("mongodb://mongo-0.mongo:27017,mongo-1.mongo:27017/cool_db")
  &gt;&gt;&gt; db = client.cool_db
  &gt;&gt;&gt; print db.cool_collection.count()
  Traceback (most recent call last):
   File "&lt;stdin&gt;", line 1, in &lt;module&gt;
   File "/usr/lib64/python2.7/site-packages/pymongo/collection.py", line 1800, in count
     return self._count(cmd, collation, session)
   File "/usr/lib64/python2.7/site-packages/pymongo/collection.py", line 1600, in _count
     _cmd, self._read_preference_for(session), session)
   File "/usr/lib64/python2.7/site-packages/pymongo/mongo_client.py", line 1454, in _retryable_read
     read_pref, session, address=address)
   File "/usr/lib64/python2.7/site-packages/pymongo/mongo_client.py", line 1253, in _select_server
     server = topology.select_server(server_selector)
   File "/usr/lib64/python2.7/site-packages/pymongo/topology.py", line 235, in select_server
     address))
   File "/usr/lib64/python2.7/site-packages/pymongo/topology.py", line 193, in select_servers
     selector, server_timeout, address)
   File "/usr/lib64/python2.7/site-packages/pymongo/topology.py", line 209, in _select_servers_loop
     self._error_message(selector))
  pymongo.errors.ServerSelectionTimeoutError: mongo-0.mongo:27017: [Errno -2] Name or service not known,mongo-1.mongo:27017: [Errno -2] Name or service not known
  </code></pre>
  
  <p>If we use the Endpoint IP Address, then we will get a response from DB.</p>
  
  <pre><code>&gt;&gt;&gt; import pymongo
  &gt;&gt;&gt; client = pymongo.MongoClient("mongodb://10.244.1.8,10.244.2.9:27017/cool_db")
  &gt;&gt;&gt; db = client.cool_db
  &gt;&gt;&gt; print db.cool_collection.count()
  0
  &gt;&gt;&gt; 
  </code></pre>
  
  <p>I have tried with different URI's like (client = pymongo.MongoClient("mongodb://mongo-0.mongo:27017/cool_db") )but not working. Could anyone please help me?</p>