Install and Set Up Mongoose Help Please!

Install and Set Up Mongoose Help Please!
0
#1

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:[email protected]: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:[email protected]: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!!

0 Likes

#2

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.

0 Likes

#3

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!

0 Likes

#4

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

0 Likes

#5

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

0 Likes

#6

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.

0 Likes

#7

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!

0 Likes

#8

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

also follow these instructions in the docs

0 Likes

#9

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

0 Likes

#10

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

mongodb+srv://mscanza:[email protected]/test?retryWrites=true;

I can’t connect to Mongoose…

Please let me know if/how you fix it!

0 Likes