I’m using VSCode, and installed Mongoose and MongoDB
npm install mongodb
npm install mongooose
Created .env file and add the URI
Reading the doc, the only way I can connect to the dabase is with the following code
const { MongoClient } = require("mongoose");
MongoClient.connect(process.env.MONGO_URI, { useNewUrlParser: true, useUnifiedTopology: true })
When I start the server, I get any error. I can see a webpage with the following:
** MongoDB & Mongoose**
When I tried to send my solution link, I get this error:
// running tests
"mongoose version ^5.11.15" dependency should be in package.json
"mongoose" should be connected to a database
// tests completed
I tried the following code:
const { mongoose } = require("mongoose");
mongoose.connect(process.env.MONGO_URI, { useNewUrlParser: true, useUnifiedTopology: true })
But, this way I can’t connect. This error shows up:
TypeError: mongoose.connect is not a function
This is my package.json file:
{
"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.18.2",
"mongodb": "^5.0.1",
"mongoose": "^5.13.15"
},
"repository": {
"type": "git",
"url": "https://github.com/freeCodeCamp/boilerplate-mongomongoose.git"
},
"keywords": [
"node",
"mongoose",
"express"
],
"license": "MIT"
}
And this is an example of my .env file:
MONGO_URI='mongodb+srv://myusername:mypassword@cluster0.n2iu8mg.mongodb.net/Cluster0?retryWrites=true&w=majority'
Idk what else I can do. Anyone, pls can help me?