title: MongoDB unescaped slash in user info section while building a serverless function hosted by Vercel
body: <p>I'm hosting a website with Vercel, built in React and with serverless functions through them.</p>
  <p>I've created a function that posts to my MongoDB database using Mongoose.</p>
  <p>However, I can't connect to my database - it comes up with the following error:</p>
  <pre><code>c5021f92-4dcc-49de-89c9-7a00203be4e0    ERROR   Unhandled Promise Rejection     {&quot;errorType&quot;:&quot;Runtime.UnhandledPromiseRejection&quot;,&quot;errorMessage&quot;:&quot;MongoParseError: Unescaped slash in userinfo section&quot;,&quot;reason&quot;:{&quot;errorType&quot;:&quot;MongoParseError&quot;,&quot;errorMessage&quot;:&quot;Unescaped slash in userinfo section&quot;,&quot;name&quot;:&quot;MongoParseError&quot;,&quot;stack&quot;:[&quot;MongoParseError: Unescaped slash in userinfo section&quot;,&quot;    at parseConnectionString (/var/task/node_modules/mongodb/lib/core/uri_parser.js:603:21)&quot;,&quot;    at QueryReqWrap.callback (/var/task/node_modules/mongodb/lib/core/uri_parser.js:114:7)&quot;,&quot;    at QueryReqWrap.onresolve [as oncomplete] (dns.js:205:10)&quot;]},&quot;promise&quot;:{},&quot;stack&quot;:[&quot;Runtime.UnhandledPromiseRejection: MongoParseError: Unescaped slash in userinfo section&quot;,&quot;    at process.&lt;anonymous&gt; (/var/runtime/index.js:35:15)&quot;,&quot;    at process.emit (events.js:327:22)&quot;,&quot;    at processPromiseRejections (internal/process/promises.js:209:33)&quot;,&quot;    at processTicksAndRejections (internal/process/task_queues.js:98:32)&quot;]}
  Unknown application error occurred
  </code></pre>
  <p>I've built my connection string like this, after doing some research into environment variables and MongoDB with Vercel.</p>
  <pre><code>mongoose.connect(`mongodb+srv://${process.env.MONGO_USER}:${process.env.MONGO_PASSWORD}@database.f9twk.mongodb.net/@otter-money?retryWrites=true&amp;w=majority`, {useNewUrlParser: true});
  </code></pre>
  <p>My question is a) what am I doing wrong in that string? I'm using template literals so not sure why it's not happy with it. and b) is there a better way to approach this?</p>
  <p>I've tried the full string as a mongoURI in my env, but no luck.</p>