MongoDB and Mongoose - Install and Set Up Mongoose

MongoDB and Mongoose - Install and Set Up Mongoose
0

Hey Dereje1,
I think all steps suggested in your links were taken. IP addresses where white listed.

.

Here is a link to my Glitch.
ttps://glitch.com/edit/#!/orchid-purple?path=.glitch-assets:1:0
Great thanks in advance

If you click on allow all ip addresses you should see 0.0.0.0/0 (includes your current IP address) included in your ip address list, which means you may not have done it correctly. Your glitch app connects fine for me with my own connection string…

2 Likes

Thank you Good Sir. It’s working fine now.

good, I have merged your thread to the main one

Hi, I’ve encountered an issue with this exercise. I believe my code is correct, however when I submitted my solution, all the tests failed, and I saw this error message on the Chrome console:

“Access to XMLHttpRequest at ‘/package.json’ from origin ‘’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.”

Does anyone know how I can fix this?

thanks for the tip on allowing all ip addresses on glitch, i was running around in circles trying to figure out why it wasnt working!

thank you … i got stuck in the lessons instructions …

Thank you so much for this. :slight_smile:

1 Like

thanks, this was really helpful.

If your password in plain-text is [email protected]'9'! , you would need to encode your password as:

p%40ssw0rd%279%27%21

I was stuck on this challenge too using Mongo Atlas. I had an ‘&’ in my MONGO_URI which made the process.env.MONGO_URI variable undefined. So I escaped the & by putting a \ before it and then my test passed.

My working MONGO_URI looks like:

MONGO_URI=mongodb+srv://username:[email protected]/test?retryWrites=true\&w=majority

If you notice that after “retryWrites=true” I put a slash before the &. This change helped my myApp.js read my process.env.MONGO_URI variable.

1 Like

I have crosschecked everything mongodb to glitch, still not working. Says not found if i use the live link, but here’s the code link : https://glitch.com/edit/#!/fifth-blade?path=package.json:1:0 .Thanks.

I’ve tried everything in this thread and still can’t get the test to pass. I’m really at a loss here.

The freecodecamp console logs:
Unexpected token < in JSON at position 0
Unexpected token < in JSON at position 0
mongoose is not connected

And the only thing I get in the glitch log is:
Could not find node 4.4.5, using 10
Your app is listening on port 3000

Here is what I have in my glitch project:

.env file

SECRET=
MADE_WITH=
MONGO_URI=mongodb+srv://test:[email protected]/test

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

and the only lines I added to myApp.js

var mongodb = require('mongodb');
const mongoose = require('mongoose');
mongoose.connect(process.env.MONGO_URI,{useNewUrlParser: true});

Does anyone know what the issue might be?

Edit: hours of effort and all I had to do was use the Live App link for glitch and not the Project Page link

In you .env file, wrap your MONGO_URI in single quotes.

Like so:

MONGO_URI='mongodb+srv://<username>:<password>@cluster0-bvw5o.mongodb.net/test?retryWrites=true&w=majority'
1 Like

still not working; you can check mine few days ago.

@RobotFights update your depedencies.

done that again, still not going. Going crazy here.

It need be mongoose.connect(process.env.MONGO_URI) without {useNewUrlParser: true}

@opereverzeva still not going, cant seem to find the fault here.

Can you put up the connection string you are trying to use (x out or put password in place of your real password).