title: MongoDB connection error: MongoParseError: Invalid connection string
body: <p>I need to connect to my DB. When I hit <code>npm start</code> in my cli, this error pops up...</p>
  <p>I've looked online for similar issues but people have one line of code similar to this one:</p>
  <pre class="lang-js prettyprint-override"><code>mongoose.connect(`mongodb://${process.env.DB_USER}:${process.env.DB_PASSWORD}@db:27017/${process.env.DB_NAME}`, {useNewUrlParser: true});
  </code></pre>
  <p>In my case, I only have an <code>.env</code> file with my logs. I've tried to put this inside my server.js file but it didn't work.</p>
  <p>here's the error :</p>
  <pre class="lang-sh prettyprint-override"><code>MongoDB connection error: MongoParseError: Invalid connection string
      at parseConnectionString (/home/mathieu/projects/techproject/shopster/node_modules/mongodb/lib/core/uri_parser.js:565:21)
      at connect (/home/mathieu/projects/techproject/shopster/node_modules/mongodb/lib/operations/connect.js:282:3)
      at /home/mathieu/projects/techproject/shopster/node_modules/mongodb/lib/mongo_client.js:223:5
      at maybePromise (/home/mathieu/projects/techproject/shopster/node_modules/mongodb/lib/utils.js:662:3)
      at MongoClient.connect (/home/mathieu/projects/techproject/shopster/node_modules/mongodb/lib/mongo_client.js:219:10)
      at /home/mathieu/projects/techproject/shopster/node_modules/mongoose/lib/connection.js:791:12
      at new Promise (&lt;anonymous&gt;)
      at NativeConnection.Connection.openUri (/home/mathieu/projects/techproject/shopster/node_modules/mongoose/lib/connection.js:788:19)
      at /home/mathieu/projects/techproject/shopster/node_modules/mongoose/lib/index.js:342:10
      at /home/mathieu/projects/techproject/shopster/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:5
      at new Promise (&lt;anonymous&gt;)
      at promiseOrCallback (/home/mathieu/projects/techproject/shopster/node_modules/mongoose/lib/helpers/promiseOrCallback.js:30:10)
      at Mongoose.connect (/home/mathieu/projects/techproject/shopster/node_modules/mongoose/lib/index.js:341:10)
      at Object.&lt;anonymous&gt; (/home/mathieu/projects/techproject/shopster/models/ProductModel.js:4:10)
      at Module._compile (internal/modules/cjs/loader.js:936:30)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10) {
    name: 'MongoParseError'
  }
  
  </code></pre>