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
You can find everything at https://glitch.com/edit/#!/absorbing-heliotrope-wash though.
Any help would be much appreciated.
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
Eddie
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://Pufferfish101007:MYPASSWORD@256-shades-of-grey.wxdzx.mongodb.net/test?retryWrites=true&w=majority
Yep.
Can you try this?
TL;DR: Try using
encodeURIComponent()
@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');
if(err){console.log(err)}
})
I just know this works, so we can eliminate problems that can be causing the issue
You might need to whitelist the IP 0.0.0.0/0 to allow access from anywhere (and Glitch).
@khalby786 I have indeed whitelisted 0.0.0.0/0
@EddiesTech It’s still returning the error, but when I URI encode it the errror’s shorter
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.