MongoDB and Mongoose - Install and Set Up Mongoose - Unable to resolve the issue

This has been mentioned by other members as well but I’ve applied all the changes and still it’s not working.

Here are the errors that I’m facing:

  1. “mongoose” should be connected to a database
  2. “mongodb” dependency should be in package.json
  3. “mongoose” dependency should be in package.json

And here’s my code:

Env File:

MONGO_URI=mongodb://<username>:<password>@ds041377.mlab.com:41377/freecodecamp-1

The username and password have been replaced with my username and password (without “<” and “>”).
Second, there’s no special character in the password. Just alpha numeric.

I’ve checked the output of process.env.MONGO.URI and it’s generating the correct output so apparently my env configuration is all right.

Here’s my package.json file

{
	"name": "fcc-learn-node-with-express",
	"version": "0.1.0",
	"dependencies": {
		"express": "^4.14.0",
		"body-parser": "^1.15.2",
		"cookie-parser": "^1.4.3",
		"fcc-express-bground": "https://github.com/Em-Ant/fcc-express-bground-pkg.git",
    "mongodb": "^3.0.10",
    "mongoose": "^5.1.6"
	},
	"main": "server.js",
	"scripts": {
		"start": "node server.js"
	},
	"engines": {
		"node": "4.4.5"
	}
}

And here’s myApp.js file:

const mongoose = require('mongoose');
mongoose.connect(process.env.MONGO_URI);

So guys, what am I missing? Everything seems to be perfectly fine but still it’s giving the above errors.

Would love to be offered a helping hand here.

Thank you.

Try saving the connection to a variable:

`let connection = mongoose.connect(process.env.MONGO_URI);

Did that. Still the same error.

Can you please confirm the URL that I should be entering in FreeCodeCamp?

Currently, I’m entering: https://lapis-golf.glitch.me/

Thank you.

Ok, it was a dumb mistake after all.

I was entering the same test URL that I was using for the previous exercises.

Never saw the link at the very first introductory chapter which should be used for these exercises.

So there was nothing wrong with the code.

It’s resolved now.

1 Like

good find. It’s the little things that bite us in the butt… :wink:

Exactly. That’s truly irritating.

Hi, in the new version of mongoose you have to add one more option(the object with 2 props) :
mongoose.connect(process.env.MONGO_URI, {useNewUrlParser: true,useUnifiedTopology: true});

1 Like

I was having an issue because, although I had successfully replaced the username, password and database fields in the URI provided by MongoDB Atlas, it ended with &w=majority. I could successfully submit the exercise after removing this piece of text.

I was also trying to submit the link for the Project Page, not the Live App link.
At Glitch.com, you need to go on [Share] and choose the [Live App] tab, then copy the link.

It looks like https://probably-sincere-kiwi.glitch.me
Not https://glitch.com/~probably-sincere-kiwi