title: Connecting mongodb to app in kubernetes cluster
body: <p>I want to connect to mongo pod in k8s and the uri address is wrong.
  The address is</p>
  <pre><code>mongo &quot;mongodb://eli:1234@calocalc-chart-mongodb-0.mongodb-headless.default.svc.cluster.local:27017/calocalcdb?replicaSet=rs0&amp;authSource=admin&quot;
  </code></pre>
  <p>Whatever i do it gives me this error:</p>
  <pre><code>root@mongo:/# mongo &quot;mongodb://eli:1234@calocalc-chart-mongodb-0.mongodb-headless.default.svc.cluster.local:27017/calocalcdb?replicaSet=rs0&amp;authSource=admin&quot;
  MongoDB shell version v5.0.3
  connecting to: mongodb://calocalc-chart-mongodb-0.mongodb-headless.default.svc.cluster.local:27017/calocalcdb?authSource=admin&amp;compressors=disabled&amp;gssapiServiceName=mongodb&amp;replicaSet=rs0
  {&quot;t&quot;:{&quot;$date&quot;:&quot;2021-11-02T10:15:00.806Z&quot;},&quot;s&quot;:&quot;I&quot;,  &quot;c&quot;:&quot;NETWORK&quot;,  &quot;id&quot;:4333208, &quot;ctx&quot;:&quot;ReplicaSetMonitor-TaskExecutor&quot;,&quot;msg&quot;:&quot;RSM host selection timeout&quot;,&quot;attr&quot;:{&quot;replicaSet&quot;:&quot;rs0&quot;,&quot;error&quot;:&quot;FailedToSatisfyReadPreference: Could not find host matching read preference { mode: \&quot;nearest\&quot; } for set rs0&quot;}}
  Error: Could not find host matching read preference { mode: &quot;nearest&quot; } for set rs0, rs0/calocalc-chart-mongodb-0.mongodb-headless.default.svc.cluster.local:27017 :
  connect@src/mongo/shell/mongo.js:372:17
  @(connect):2:6
  exception: connect failed
  exiting with code 1
  
  </code></pre>
  <p>I also tried to add a username and password at the beginning of the URI and it gives the same results.
  The name of the pod is correct and i installed it via helm and disabled the arbiter.
  I have 3 mongo pods but i just want to connect to a single one right now and when it will work i will try to connect to the other 2 as well.</p>
  <p>If any other info is required pls tell me and i will update this thread.</p>