Install and Set Up Mongoose on Replit


First of, I already searched forum, but the problem cannot be resolved by following those suggestions already given. Replit no longer accepts .env files and FCC guide is now outdated. Hence, asking over again.

Tell us what’s happening:
I managed to find the way to connect to my MongoDB database circumventing need for .env file. For this I have copied full driver code example generated on MongoDB’s ‘Connect to Cluster’ section. So when I run a code on Replit I am able to connect to Mongo database. But FCC test fails throwing this error: ‘“mongoose” should be connected to a database’.

Was anyone able to pass FCC test recently. If so how you did it please?

Your help is desperately needed.

Your project link(s)


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36

Challenge: Install and Set Up Mongoose

Link to the challenge:

Welcome there,

The guide is a bit outdated, but all the information is relevant. Replit just moved to using their SECRETS tab for environment variables. Otherwise, the mechanics are the same:

  • Add an environment variable and give it a value
  • Access the environment variable value with process.env.<variable_name>

I belive the reason the tests are failing for you is because you are not connecting Mongoose:

mongoose.connect(<Your URI>, { useNewUrlParser: true, useUnifiedTopology: true });

You are connecting MongoDB:

const client = new MongoClient(uri, { useNewUrlParser: true, useUnifiedTopology: true });

The code has been given to you to connect. All you need to do is replace the <Your URI> with process.env.MONGO_URI

Then, provided the value you have for MONGO_URI is correct, Mongoose should be connected

Hope this helps

Thank you for confirming that FCC tests are not outdated and still working. I much needed that assurance.

I was able to pass all 3 tests after starting on new Replit repository and following FCC guides but only changing the bit concerning .env files.

To whomever needs guidance, this is how I did it:

  1. Add mongodb@~3.6.0 and mongoose@~5.4.0 to the project’s package.json.
  2. Then, require mongoose as mongoose in myApp.js.
  3. Add MONGO_URI key in Replit’s secrets and paste the URI value copied from MongoDB Atlas database URI. No need to add single or double quotes, just copy+paste. You only need to change password here.
  4. Replit’s secrets are hidden and you can make use of by inserting process.env['MONGO_URI'] wherever you need that value (URI in our case).
  5. Next is simply copy+paste following code:
mongoose.connect(<Your URI>, { useNewUrlParser: true, useUnifiedTopology: true });

and replace <Your URI> with process.env['MONGO_URI']

That’s it! You will pass the FCC tests.

Hope this helps.
Thank you all

1 Like

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