Install and Set Up Mongoose Help Please!

Hi Everyone,

I have been stuck on this challenge for over a week trying to figure out what I did wrong. Can anyone please point out where my error is?

This is my .env file

GLITCH_DEBUGGER=true
# Environment Config

# store your secrets and config variables in here
# only invited collaborators will be able to see your .env values

# reference these in your code with process.env.SECRET

SECRET=
MADE_WITH=
MONGO_URI=mongodb://chrisjohnson0390:myPassword@ds123625.mlab.com:23625/freecodecamp_mongo

# note: .env is a shell file so there can't be spaces around =

This is my app.js

const mongoose = require("mongoose");

mongoose.connection.on("open", function(ref) {
  console.log("Connected to mongo server.");
});

mongoose.connection.on("error", function(err) {
  console.log("Could not connect to mongo server!");
  return console.log(err);
});

const mongoURI = "mongodb://chrisjohnson0390:myPassword@ds123625.mlab.com:23625/freecodecamp_mongo";

const db = mongoose.connect(mongoURI, { useNewUrlParser: true });

And this is my package.json

{
	"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",
    "mongoose": "^5.1.6",
    "mongodb": "^3.4.13"
	},
	"engines": {
		"node": "4.4.5"
	},
	"repository": {
		"type": "git",
		"url": "https://hyperdev.com/#!/project/welcome-project"
	},
	"keywords": [
		"node",
		"hyperdev",
		"express"
	],
	"license": "MIT"
}

When I run the test this is the error that I get:

// running tests

mongoose is not connected

Unexpected token < in JSON at position 0

Unexpected token < in JSON at position 0

// tests completed

Any help is greatly appreciated!!

I’ve been noticing more of these errors on the mongoose challenges since mlab became a part of mongoDB and changed some of the connection strings, need to check with a brand new mlab account if it really is the case and affecting those challenges.

This is my second account I’ve used. I had one set up for a web developer boot camp I took recently. That account works fine connected to my app I have hosted in Heroku.

Neither account passes the test and honestly I don’t even understand what the error means!

post your glitch link, I’ll test it with my own mlab connection string

I just created the account for this forum so it doesn’t trust my links yet sorry! Please add the https.

://glitch.com/~petite-snout

Without doing any changes, your code connects to the db and passes the challenge for me using your own connection string, which you left public btw since you did not put it in your .env file. Check if it is an issue of access from your glitch (whitelisting, etc…), as it is not a problem with your code or connection string.

Yeah at this point I said screw it about security for the DB. I moved the code out of the env to see if that is an issue at all.

I’m back at work now and can’t acess my personal laptop so I’ll have to check later.

Thank you for looking into this!

put the URI and const db directly after const mongoose = require();

also follow these instructions in the docs

This happened to me a couple times. I would refresh Glitch and it would work. Maybe try refreshing the page?

Been having the same issue for 3 days now. I can’t get an mlab uri, I have the new uri:

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

I can’t connect to Mongoose…

Please let me know if/how you fix it!

I have the same problem!