Install and Set Up Mongoose - Won't connect to database

Hello, I seem to be stuck setting up my database using mongodb and connecting through mongoose. This is being run on glitch through the fcc boilerplate.
My .env file

MONGO_URI=mongodb://dbuser:dbpassword@ds0<PORT>.mlab.com:<PORT>/<DATABASE-NAME>

Where I have replaced the placeholders with all of my info

My myApp.js file

var mongoose = require('mongoose');

mongoose.connect(process.env.MONGO_URI);

And my package.json file

{
	"name": "fcc-mongo-mongoose-challenges",
	"version": "0.0.1",
	"description": "A boilerplate project",
	"main": "server.js",
	"scripts": {
		"start": "node server.js"
	},
	"dependencies": {
		"express": "^4.12.4",
		"body-parser": "^1.15.2",
    "mongodb": "^3.1.13",
    "mongoose": "^5.4.14"
	},
	"engines": {
		"node": "10.15.1"
	},
	"repository": {
		"type": "git",
		"url": "https://hyperdev.com/#!/project/welcome-project"
	},
	"keywords": [
		"node",
		"hyperdev",
		"express"
	],
	"license": "MIT"
}

I am getting an UnhandledPromiseRejectionWarning error and when I run it through the fcc test it detects the mongodb and mongoose dependencies but throws out

// running tests
mongoose is not connected
// tests completed

and fails the mongoose should be connected to a database test.

Any help would be appreciated!

1 Like

double check your connection string, if you want, you can post a link to your glitch file and I can check with a working connection string if that really is your problem. For example
here @ds0 the zero is not a constant, all you have to do is only replace the dbuser and dbpassword fields from the template mlab provides.

That would be great if you could check it with a working connection. Here’s a link to my glitch:

Just checked, it works fine with a working connection string, other than a deprecation warning due to not passing { useNewUrlParser: true } option to client, but that is normal, so again check your connection string.

I managed to fix the issue. It seemed to be a whitelisting issue I had. Thank you for the help.

What is the solution to this problem? I’m having the exact same issue where I can’t connect to Mongoose. I made sure to whitelist my ip address, does not fix the problem. Also, my uri looks different, as it is no longer possible to get an mlab uri. The current uri looks like:

mongodb+srv://mscanza:password@fcc-vcnna.mongodb.net/test?retryWrites=true

Could this be why it is not connecting?

1 Like

If you still haven’t figured it out try setting the whitelist to anywhere.

1 Like

Hi @murphloool,

The issue is that the FCC instructions were made before the acquisition of mlab by mongodb Atlas and need to be updated, but meanwhile, here is a list of things that need to be done that I am updating as things show up to make the lessons work.

In order to keep things related specifically to this topic in a thread I can track, I am locking this one and other similar threads that may pop up as more users attempt to do these lessons.

Thanks for understanding,
Dereje.