Home > Back-end >  App is not connecting to the mongodb Atlas
App is not connecting to the mongodb Atlas

Time:09-17

I start learning JavaScript on the freecodecamp and stuck on a challenge.

The challenge itself is to setup a mongoose. But every time I am submitting my answer it giving me an error of "mongoose should be connected to a database.

I checked the fcc forum on the same topic and all of the solutions not working for me

The challenge provide the starting code and all what is required is to setup mongo atlas and connect your app to it

In the app.js you should add

    require("dotenv").config();
    let mongoose = require("mongoose");

    mongoose.connect(process.env.MONGO_URI, {
      useUnifiedTopology: true,
      useNewUrlParser: true
    });

in the .env file MONGO_URI=mongodb srv://userName:[email protected]/myFirstDatabase

Where the userName and password are changed to mine without any prohibited symbols.

You should also add this dependencies to package.json

    "mongodb": "4.1.1",
    "mongoose": "6.0.5"

Any help appreciated

CodePudding user response:

Can you try to change connection config and use it without additional options:

mongoose.connect(process.env.MONGO_URI);

Since you are using Mongoose version higher than 6.0, these options are not available as config anymore, and are configured automatically.

  • Related