title: mongodb how to get the correct uri
body: <p>I've inherited node.js, mongodb system.</p>
  
  <p>The original dev used a mlab db on his own account, I was asked to copy to a different db.</p>
  
  <p>When I tried to create a mlab user I was redirected to cloud.mongodb.com (which apparently purchase mlab)</p>
  
  <p>I was struggling to create a DB and connect to it through <code>robo 3t</code> and <code>Compass</code>, and now I'm able to connect and query the DB.</p>
  
  <p>I used Compass export/import collection to copy the DB (was not able to copy in any other way)</p>
  
  <p>Now I set the db uri in my app to the new db but it hangs when I do findOne</p>
  
  <p>here is the old uri:</p>
  
  <p><code>mongodb://dekel:password@ds115094.mlab.com:15094/somebuddy</code></p>
  
  <p>therefore I assumed the connection string should be:</p>
  
  <p><code>mongodb://root:password@cluster0-shard-00-00-jjbdh.mongodb.net:27017/somebuddy</code></p>
  
  <p>I get </p>
  
  <p><code>UnhandledPromiseRejectionWarning: MongoNetworkError: connection 0 to cluster0-shard-00-00-jjbdh.mongodb.net:27017 closed</code></p>
  
  <p>when I connect with <code>robo 3t</code> I have to set the Database to <code>admin</code> other wise I get: <code>Network is unreachable.</code></p>
  
  <p>therefore I tried the following </p>
  
  <p><code>mongodb://root:password@cluster0-shard-00-00-jjbdh.mongodb.net:27017/admin</code></p>
  
  <p>I get:</p>
  
  <p><code>MongoNetworkError: connection 0 to cluster0-shard-00-00-jjbdh.mongodb.net:27017 closed</code></p>
  
  <p>The Mongodb site says that the connection string should be </p>
  
  <p><code>mongodb+srv://root:&lt;password&gt;@cluster0-shard-00-00-jjbdh.mongodb.net/test?retryWrites=true</code></p>
  
  <p>This is very strange since <code>cluster0-shard-00-00-jjbdh.mongodb.net</code> doesn't work on <code>robo 3t</code> and <code>Compass</code>, so I guess it is only an example.</p>
  
  <p>I tired the following</p>
  
  <p><code>mongodb+srv://root:password@cluster0-shard-00-00-jjbdh.mongodb.net:27017/somebuddy</code> </p>
  
  <p>I get: </p>
  
  <p><code>Error: querySrv ENOTFOUND _mongodb._tcp.cluster0-shard-00-00-jjbdh.mongodb.net</code></p>
  
  <p>I tried with the following different users</p>
  
  <p><a href="https://i.stack.imgur.com/ClZqQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ClZqQ.png" alt="enter image description here"></a></p>
  
  <p>when I tried to use the chat on the mongodb website I get:
  <code>The team will get back to you on this. MongoDB Cloud Chat will be back tomorrow.</code></p>
  
  <p>this is what I get when i try to connect with the shell (see <a href="https://www.youtube.com/watch?v=Ej05tq1220A" rel="nofollow noreferrer">https://www.youtube.com/watch?v=Ej05tq1220A</a>):</p>
  
  <pre><code>C:\Program Files\MongoDB\Server\4.0\bin&gt; .\mongo.exe "mongodb+srv://cluster0-jjbdh.mongodb.net/test" --username root
  MongoDB shell version v4.0.8
  Enter password:
  connecting to: mongodb://cluster0-shard-00-01-jjbdh.mongodb.net.:27017,cluster0-shard-00-02-jjbdh.mongodb.net.:27017,cluster0-shard-00-00-jjbdh.mongodb.net.:27017/test?authSource=admin&amp;gssapiServiceName=mongodb&amp;replicaSet=Cluster0-shard-0&amp;ssl=true
  2019-04-07T19:03:46.945+0300 I NETWORK  [js] Starting new replica set monitor for Cluster0-shard-0/cluster0-shard-00-01-jjbdh.mongodb.net.:27017,cluster0-shard-00-02-jjbdh.mongodb.net.:27017,cluster0-shard-00-00-jjbdh.mongodb.net.:27017
  2019-04-07T19:03:58.840+0300 W NETWORK  [js] Unable to reach primary for set Cluster0-shard-0
  2019-04-07T19:03:58.841+0300 I NETWORK  [js] Cannot reach any nodes for set Cluster0-shard-0. Please check network connectivity and the status of the set. This has happened for 1 checks in a row.
  2019-04-07T19:04:00.281+0300 W NETWORK  [js] Unable to reach primary for set Cluster0-shard-0
  2019-04-07T19:04:00.282+0300 I NETWORK  [js] Cannot reach any nodes for set Cluster0-shard-0. Please check network connectivity and the status of the set. This has happened for 2 checks in a row.
  2019-04-07T19:04:01.751+0300 W NETWORK  [js] Unable to reach primary for set Cluster0-shard-0
  2019-04-07T19:04:01.752+0300 I NETWORK  [js] Cannot reach any nodes for set Cluster0-shard-0. Please check network connectivity and the status of the set. This has happened for 3 checks in a row.
  2019-04-07T19:04:01.756+0300 E QUERY    [js] Error: connect failed to replica set Cluster0-shard-0/cluster0-shard-00-01-jjbdh.mongodb.net.:27017,cluster0-shard-00-02-jjbdh.mongodb.net.:27017,cluster0-shard-00-00-jjbdh.mongodb.net.:27017 :
  connect@src/mongo/shell/mongo.js:343:13
  @(connect):2:6
  exception: connect failed
  </code></pre>
  
  <p>and</p>
  
  <pre><code>.\mongo.exe "mongodb://root:password@cluster0-shard-00-00-jjbdh.mongodb.net:27017/admin"
  MongoDB shell version v4.0.8
  connecting to: mongodb://cluster0-shard-00-00-jjbdh.mongodb.net:27017/admin?gssapiServiceName=mongodb
  2019-04-07T19:17:19.420+0300 E QUERY    [js] Error: network error while attempting to run command 'isMaster' on host 'cluster0-shard-00-00-jjbdh.mongodb.net:27017'  :
  connect@src/mongo/shell/mongo.js:343:13
  @(connect):2:6
  exception: connect failed
  </code></pre>