MongoDB and Mongoose - Install and Set Up Mongoose need help!

"dependencies": {
		"express": "^4.12.4",
		"body-parser": "^1.15.2",
    "mongodb" : "^3.6.8",
    "mongoose" : "^5.3.9"
	},

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

MONGO_URI=mongodb://simba:$123simba@ds131963.mlab.com:31963/databazz

The error says mongoose isn’t connected…plzz help!!

Hi, I think you don’t need to add mongo dependency. But you need to import .env, and add the uri in .env file.
Check on your mlab account the exact url of the db, it includes mongodb:// at begining.

Best regards

You called MONGO_URI before you set the actual variable.

Put the line below before the one about mongoose.connect()

const MONGO_URI="mongodb://simba:$123simba@ds131963.mlab.com:31963/databazz"

Follow this Getting Started instructions from the mongoose docs for more details.

I’ve included mongodb:// in the beginning,…it’s still not working…

It’s not working…!!!

You’re reading the MONGO_URI from process.env, did you setup that correctly? If not you can always use directly like:

const mongoose = require('mongoose');
mongoose.connect('simba:$123simba@ds131963.mlab.com:31963/databazz');

Can anyone help…I’ve now deleted the previous user and changed the password in a way that it not includes special characters…still it’s showing error.

I got the perfect solution
mongoose.connect(process.env.MONGO_URI, { useNewUrlParser: true });
use this and at private environment file use your database name and database password and the test will pass

Which file did you add this on?

Figured it out, in the myApp.js. The { useNewUrlParser: true } isn’t necessary.

Has anybody been able to do this with the new uri? You can’t get an mlab uri anymore…

This is the new URI:
mongodb+srv://mscanza:password@fcc-vcnna.mongodb.net/test?retryWrites=true

I’ve been unable to connect to Mongoose. Any help would be greatly appreciated. It passes the dependencies tests. The error keeps saying:

(node:6705) UnhandledPromiseRejectionWarning: MongoNetworkError: connection 4 to fcc-shard-00-00-vcnna.mongodb.net:27017 closed

Were you able to figure this out? I’m having a similar issue

Yes, this may help: