I did all the required steps (followed a video on how to do it) but still get the error:
““mongoose” should be connected to a database error”
Also in the console I see this error:
“(node:601) UnhandledPromiseRejectionWarning: MongoParseError: URI malformed, cannot be parsed”
Do you know where my code may be wrong or what I’m doing wrong?
The following are screenshots of everything that I think could possibly be wrong:
Your project link(s)
Your browser information:
User Agent is:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36
Challenge: Install and Set Up Mongoose
Link to the challenge:
try changing your
Also, inside your URI string, you can change “myFirstDatabase” into whatever name you want the collection to be ( this may come in handy later)
Thanks for the suggestion
Just tried it, didn’t work
Any other ideas?
(I’ve also removed the ‘<’ and ‘>’ symbols surrounding my password, shown below, which I believe should not have been there in the first place, and that did not work either)
Correct, they should not be there. Also, now I remember why I stopped using Replit, this exact reason. I could never get the secrets editor to work, so I just copied everything over to glitch.com on their editor and it worked fine. I think it has something to do with the way it formats.
My .env on any other editor appears like this:
Aside from that, the only other thing I can think of that was stopping me from connecting was that I was using my account name and password (doesn’t work) instead of my authorized user name and password. Beside that I am not sure, never could get Replit to work with my database and also could not find an answer for making it work. I just went to Glitch (or codesandbox) because your .env file works exactly the same as VSCode (just name a file .env and input your secrets).
I wish I had the actual answer because it would have saved me a day of troubleshooting a couple months ago.
So, you have a malformed URI. Setting
MONGO_URI to the string you get from your MongoDB account like
mongodb+srv://user:pass@cluster... in repl.it secrets editor will work, even without using the advanced version. The user has to be the database user and its password, not the username/password you use to login to your cloud.mongodb.com account.
The URI is available from the project page (with the graphs). Click “connect” above the graphs and then select the “connect your application” option. Copy the URI and replace
<password> with your database user password which is editable from the project page by selecting “database access” under “security” on the left and then editing the appropriate user.
I forked your project, added by credentials, and passed the test without incident.
Thanks for your suggestions, greatly appreciated
In the end the problem was that my password contained a ‘%’ symbol, which needed to be encoded to ‘%25’ in the URI for the URI to work
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.