Mongodb URI malformed

I’m brand new to using MongoDB, and I’m essentially following the quickstart guide in the docs. But apparently my URI is malformed… I’ve tried using the one that mongodb gives me, the one from the docs, mixing and matching them, having the password irl encoded and not url encoded, changing the mongodb version… Nothing’s working! I would copy and paste the error and the code, but I’m on mobile and nothing in the glitch editor can be copied :unamused:
You can find everything at!/absorbing-heliotrope-wash though.
Any help would be much appreciated.

Sorry for the bad explaining and spelling... I'm tired. I can edit this later if you need me to.

Are you using MongoDB Atlas?

Hi @Pufferfish101007!
I have had this issue when using the Mongoose connection string in .env. Try surrounding it in ""s. Put the whole URL (not just password) in .env and let me know what happens :slight_smile:


It is indeed in quotes, and I just tried it with the full url, it still didn’t work, the url I’m using is mongodb+srv://


Can you try this?

TL;DR: Try using encodeURIComponent()
1 Like

@EddiesTech Well, I have good news and bad news. The good news is: the URI is now not malformed! The bad news is is that it’s now an invalid connection string… any thoughts?

@Pufferfish101007 Can you try replacing your connection code with this:

mongoose.connect(process.env.MONGODB_CONNECTION_STRING,{ useUnifiedTopology: true, useNewUrlParser: true },(err) => {
  console.log('mongodb connected');

I just know this works, so we can eliminate problems that can be causing the issue


You might need to whitelist the IP to allow access from anywhere (and Glitch).


@khalby786 I have indeed whitelisted
@EddiesTech It’s still returning the error, but when I URI encode it the errror’s shorter :crazy_face:

Edit: it’s all fine now. I have learnt something very important from this experience:

The Mongodb docs is wrong

Which is worrying.

Think community tutorials will help you


Yep. W3schools seems to be working well.

1 Like