title: Cannot connect to MongoDB because of wrong URI
body: <p>I was trying to run mongoDB on node server
  <a href="https://docs.mongodb.com/drivers/node/fundamentals/connection" rel="noreferrer">Full Code here from MongoDB</a>:</p>
  <blockquote>
  <p>My mongo version: 4.4.3</p>
  <p>Node version: v15.7.0</p>
  </blockquote>
  <p>I've imported get started code from MongoDB, and here's the code:</p>
  <pre><code>const { MongoClient } = require(&quot;mongodb&quot;);
  // Connection URI
  const uri =
    &quot;mongodb+srv://sample-hostname:27017/?poolSize=20&amp;writeConcern=majority&quot;;
  // Create a new MongoClient
  const client = new MongoClient(uri);
  async function run() {
    try {
      // Connect the client to the server
      await client.connect();
      // Establish and verify connection
      await client.db(&quot;admin&quot;).command({ ping: 1 });
      console.log(&quot;Connected successfully to server&quot;);
    } finally {
      // Ensures that the client will close when you finish/error
      await client.close();
    }
  }
  run().catch(console.dir);
  </code></pre>
  <p>On terminal, when i run &quot;node app.js&quot;, it throws me following error:</p>
  <pre><code>&gt; (node:79653) Warning: Accessing non-existent property 'MongoError' of
  &gt; module exports inside circular dependency (Use `node --trace-warnings
  &gt; ...` to show where the warning was created) MongoParseError: URI does
  &gt; not have hostname, domain name and tld
  &gt;     at parseSrvConnectionString (/home/harmony/Desktop/FruitsProject/node_modules/mongodb/lib/core/uri_parser.js:50:21)
  &gt;     at parseConnectionString (/home/harmony/Desktop/FruitsProject/node_modules/mongodb/lib/core/uri_parser.js:594:12)
  &gt;     at connect (/home/harmony/Desktop/FruitsProject/node_modules/mongodb/lib/operations/connect.js:284:3)
  &gt;     at /home/harmony/Desktop/FruitsProject/node_modules/mongodb/lib/mongo_client.js:225:5
  &gt;     at maybePromise (/home/harmony/Desktop/FruitsProject/node_modules/mongodb/lib/utils.js:681:3)
  &gt;     at MongoClient.connect (/home/harmony/Desktop/FruitsProject/node_modules/mongodb/lib/mongo_client.js:221:10)
  &gt;     at run (/home/harmony/Desktop/FruitsProject/app.js:12:18)
  &gt;     at Object.&lt;anonymous&gt; (/home/harmony/Desktop/FruitsProject/app.js:21:1)
  </code></pre>