MongoDB Connection Fails Test

Hi, my name is Joseph Torres and I am having issues with one of the challenges. So I know what to do at this point here is a screenshot that I took I can’t get it to pass for some reason could I get some feedback on this, please.

Welcome, Joseph.

I have moved your reply to its own topic, as it does not relate to the original poster’s code, but your own.

Would you mind sharing a link to your project code? The failed test suggests you have not connected correctly to the database, which should show in the Repl console.

https://boilerplate-mongomongoose-2.jtorres198823.repl.co

Always require modules/packages/libraries at the top of your files.

Then, require mongoose as mongoose in myApp.js

Also, you will be using mongoose in the predefined functions. So, you cannot require it below them.

Otherwise, do you see any errors in the console? Are you sure you have created the .env file correctly, and added the correct variable in it?

would like some assistance because I am really confused

I don’t understand what I am doing wrong instead of telling show me what I am doing wrong I am a visual learner just show don’t tell me show me so that way I can understand

Right.

I think it would be best to start from the beginning. I recommend re-cloning the repo, by using the link provided on the challenge page.

Now, the boilerplate contains:

  • A server.js file with all the necessary code to test your project (you should not touch this, for this challenge).
  • A myApp.js file with some “boilerplate” code which you should not remove. Just alter it as instructed throughout the lessons.
  • A package.json file which you should not need to edit for these challenges.
  • A sample.env file which just acts as an example of what you might use in the project’s .env file. It is a common practice to see sample.env files included with open-source projects, as it will contain the necessary environment variables to run the project. If you want to, feel free to read more about using a .env file.
  • A few other files that are not necessary to edit in this section.

Now, to complete this challenge, here are the instructions broken down into steps:

  1. Add mongoose and mongodb to the package.json
  2. Within myApp.js require mongoose and store it in a variable named mongoose
  3. Create a new file. Name this file .env (the dot must be included - it is a special file)
  4. Within .env create a new variable named MONGO_URI, and give it a value of your database URI, which you created, when you followed the initial instructions here: MongoDB Atlas Tutorial – How to Get Started (freecodecamp.org)
  5. Within myApp.js connect the variable you created named mongoose to your database using the given syntax:
mongoose.connect(<Your URI>, { useNewUrlParser: true, useUnifiedTopology: true });

Replace the <Your URI> with process.env.MONGO_URI

Now, some pre-requisites:

  • It is assumed you have completed the challenges before this
  • You have some experience of working with .env files, and know how to correctly name variables
  • You have worked with package.json files, and know how to add npm packages.

Here are some specific tips for this challenge:

  • In Repl.it, you can use the shell to add packages as you would on a command line:
    image

  • For most any project, you should only require packages at the top of the file (any file you use the package). That is, before any other code, packages should be required.

  • In order to use your database, mongoose must first be connected. So, the code to connect mongoose to your database must come before any code in the file which does/might use it.

I hope this helps