MongoDB and Mongoose - Install and Set Up Mongoose

Tell us what’s happening:

I’ve been working on connecting a MongoDB database, and despite successfully connecting locally, the test environment still fails to recognize the connection. I’ve used the correct connection string from MongoDB Atlas, ensured MONGO_URI is properly configured in the .env file, and confirmed it is being read correctly. Dependencies, including mongoose (v5.11.15), are installed and verified. Despite everything working locally, the test environment continues to fail.

.env:

MONGO_URI="mongodb+srv://<username>:<db_password>@<clustername>.idw3s.mongodb.net/"

myApp.js:

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

mongoose.connect(process.env.MONGO_URI , {
    useNewUrlParser: true,
    useUnifiedTopology: true,
})

package.json:

{
  "name": "fcc-learn-node-with-express",
  "version": "0.1.0",
  "dependencies": {
    "body-parser": "^1.15.2",
    "cookie-parser": "^1.4.3",
    "dotenv": "^16.0.1",
    "express": "^4.14.0",
    "fcc-express-bground": "https://github.com/freeCodeCamp/fcc-express-bground-pkg.git",
    "mongoose": "^5.11.15"
  },
  "main": "server.js",
  "scripts": {
    "start": "node --watch server.js"
  }
}

Your project link(s)

solution: https://3000-freecodecam-boilerplate-ls84rjdy2xx.ws-us117.gitpod.io

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36

Challenge Information:

MongoDB and Mongoose - Install and Set Up Mongoose

According to your package.json file, you are not using the correct boilerplate. Use the Gitpod starter project linked to on the challenge page.

1 Like