MongoDB and Mongoose - Install and Set Up Mongoose

<%= @topic_view.topic.title %>
<%= @topic_view.topic.average_rating %> <%= @topic_view.topic.posts.count { |p| !!p.custom_fields['rating'] } %>

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).

not working, don’t think it has anything to do with my dependencies.

@patrickndifon Am suspecting its my .env file, some end it at “MONGO_URI='mongodb+srv://:@cluster0-bvw5o.mongodb.net/test?” others at “MONGO_URI='mongodb+srv://:@cluster0-bvw5o.mongodb.net/test?retryWrites=true&w=majority” , not sure which is correct.

@RobotFights I’m pretty sure your problem has nothing to do with “your code”.
You just overlooked the package.json from the boilerplate glitch loads for you automatically and left

You can just delete it or if you still want to restrict need to update the package.json to either the node version you are running on glitch or restrict the engines object in a different manner so only runs in the node versions that your code supports. :wink:

Also, you may have to look for dotenv in npm and take a read…

@gpedro I have updated all my dependencies, and changed node version: Still not working…

@RobotFights I had to end with the ? To make it work. Also don’t use any quotes in the .env file.

@eoja I also ended with 'mongodb.net/test?’ , still doesn’t work, and no quotes around either.

Still trying to fix this for months, here is my live app link https://fifth-blade.glitch.me if there’s any help

I had a problem with the .env variable, and to fix it I had to add “dotenv”: “^8.1.0” as a dependency a initialize it on the server.js file, like this:

const dotenv = require('dotenv').config()

Now I can’t get the FCC challenge to evaluate my glitch url. I keep getting this and no more:

// running tests
// tests completed

I’m getting "Missing CORS headers ‘Access-Control-Allow-Origin’ on my browser console… Any ideas why this is happening???

SOLVED
I restarted the hole thing but using the github repo and not the glitch link in the instrucctions, turns out that the glitch link clones a repo that is not updated and there are a lot of things missing. Even so I had to add the “dotenv” dependency like I said before on the post, in order to get everything working!!

thank you, you saved my day !!!

Your live app link is not helpful, it just displays “OK!”

We’re you using dotenv in your local environment? You need it in your local environment but not on glitch. There is a lot of confusion about the glitch link to submit for an answer. You have to click “show” then “app in new window” and use that URL.