MongoDB and Mongoose - Install and Set Up Mongoose

MongoDB and Mongoose - Install and Set Up Mongoose
0

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

I have been using the link to pass other projects, but now it wouldn’t work.

One place where I made a mistake (which no one here corrects) was not adding the ‘MONGO_URI’ connect link as a string. It must be added as string in the ‘.env’ file.

MONGO_URI="mongodb://dbuser:[email protected]<PORT>.mlab.com:<PORT>/<DATABASE-NAME>"

I used try…catch statement for identifying this error and log it to the console.

try {
  const mongoose = require('mongoose');
mongoose.connect(process.env.MONGO_URI);
} catch(e) {
  console.log(e);
}

Hope that helps!

done all that before, still not working: getting this error:======= (node:2135) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.