How to connect mongoose to the database?

I am having a difficult time trying to complete the first lesson, Install and Set up MongoDB and Mongoose in freeCodeCamp.

I followed from a YouTube video example, Useful Programmer who showed me how to sign up for MongoDB Atlas and connect the cluster (or database) to

I am able to pass the two freeCodeCamp requirements of having the mongodb & mongoose in the dependencies in the package.json file.

But I do not know how to get the “mongoose” connected to a database. I am so close to complete this first hurdle.

What and why am I not able to connect my mongoose to the database?

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/92.0.4515.107 Safari/537.36

Challenge: Install and Set Up Mongoose

Link to the challenge:

The link you shared is broken.

What do you mean by that?
How do I fix the link?

Did you read the instructions?

  1. Create a MongoDB Atlas account - Do you have that? → If yes, then where did you use that in your project?

I just created my MongoDB account. I created the database.

Do you’ve the URI ? e.g.


If yes, where are adding to your project?

I added that URI code in my

This is the URI code from FreeCodeCamp:
mongoose.connect(, { useNewUrlParser: true, useUnifiedTopology: true });

Oh wait, oops my mistake
I do have that URI code from the MongoDB. sorry

Oh wait, oops my mistake
I do have that URI code from the MongoDB. Sorry. How do I get the mongoose connect to database?

Hey, please mark this thread as fixed if your problem is resolved and share the solution. TY

No, still not able to connect mongoose to database for some reason. I followed from other YouTube video examples & I still don’t know why I can’t pass. Thank you for replying.

You have to

Create a .env file and add a MONGO_URI variable to it. Its value should be your MongoDB Atlas database URI.

There’s a sample sample.env in project folder, use that as a guide for syntax and then try again.

I did create an .env file & put in the same code with the proper syntax. I deleted the sample.env file since I did not need it. I still don’t know why it will not accept my Replit url code. I am still working on it. Thank you for responding.

Replit no longer allows you to create env files.
You now have to use the secrets tab on the left hand side.

I see the Secrets (environment variables) file in Replit. It’s icon is the little lock. Correct? So I need to create the MONGO_URI in there?

That is where you will place the key and value.
Screen Shot 2021-07-29 at 4.27.35 PM

Yes. I did it. I get that secret .env file & I finally got my Replit url to pass the Freecodecamp lesson.

Thank you so much! I am glad there are people to help me. Thanks again!

1 Like

@jwilkins.oboe - Good catch :clap:

6 posts were split to a new topic: Please help me with mongo install challenge

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.