Hello,
I’ve been quite stumped on this second step for Install and Setup Mongoose,
“mongoose” should be connected to a database
I’ve been unable to solve it for a while.
What should I do first?
myApp.js that matters right now:
require('dotenv').config();
const mongoose = require('mongoose');
mongoose.connect(process.env.MONGO_URI);
dependencies of package.json:
"dependencies": {
"body-parser": "^1.15.2",
"dotenv": "^8.2.0",
"express": "^4.12.4",
"mongodb": "^3.3.2",
"mongoose": "^5.11.15"
}
.env:
MONGO_URI="^3.3.2"
Links:
Please let me know if I need to add anything else, and respond simply and as soon or as late as you want.
ILM
December 17, 2024, 10:46pm
2
fdjskalfds:
MONGO_URI=“^3.3.2”
do again the stepts to get the URI, this is not a correct one for sure
ILM
December 17, 2024, 10:48pm
4
also when you ask for help, a link to the challenge would be great
Oh, sorry. I’ll do that now.
ILM
December 17, 2024, 10:51pm
6
and when you find the correct URI, don’t share it, it’s a secret password needed to get to your database
I ran out of credits, so I’m just going to work on other things on the forum for now. Hopefully, this conversation will start again around next month.
Hello again, @ILM . I got myself some more credits, so I started working again. UPDATE: I was able to fix that error, but now able to fix that error, but now a new one shows up:
Error: Invalid schema, expected mongodb
or mongodb+srv
What is wrong with my code?
sample.env:
MONGO_URI="mongodb+srv://<db_username>:<db_password>@goofy-goober.y94jf.mongodb.net/"
package.json:
{
"name": "fcc-mongo-mongoose-challenges",
"version": "0.0.1",
"description": "A boilerplate project",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"body-parser": "^1.15.2",
"dotenv": "^8.2.0",
"express": "^4.12.4",
"mongoose": "^5.11.15"
},
"repository": {
"type": "git",
"url": "https://github.com/freeCodeCamp/boilerplate-mongomongoose.git"
},
"keywords": [
"node",
"mongoose",
"express"
],
"license": "MIT"
}
myApp.js that matters:
require('dotenv').config();
const mongoose = require('mongoose');
mongoose.connect("process.env.MONGO_URI");
ILM
December 18, 2024, 10:25pm
9
did you create an .env
file from this adding the correct URI?
No… It was just there. I’ll make one right now. UPDATE: I made one, yet the error is still there.
ILM
December 18, 2024, 10:31pm
11
fdjskalfds:
mongoose.connect(
you are missing the second argument, check again challenge instructions
Actually, I did add it, I just didn’t know what to do with it.
mongoose.connect("process.env.MONGO_URI", { useNewUrlParser: true, useUnifiedTopology: true });
Sorry for replying so late.
ILM
December 19, 2024, 8:37am
13
why the first argument has become a literal string?
oh, it was even earlier, my bad to look at code when I should sleep
Good morning @ILM . It’s fine. It happens with everybody, when they’re extremely tired, they see something that’s not real at some point… At least, I hope.