MongoDB and Mongoose - Install and Set Up Mongoose

Tell us what’s happening:

Doing the Challenge via Gitpod.

dependencies:

.env file:

MONGO_URI='mongodb+srv://<myusername>:<mypassword>@cluster0.d3v9l.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0'

myApp.js

 const mongoose = require('mongoose');

mongoose.connect(process.env.MONGO_URI, {
  useNewUrlParser: true,
  useUnifiedTopology: true,
}).then(() => {
  console.log("MongoDB connection successful");
  console.log("Mongoose connection state:", mongoose.connection.readyState); 
}).catch((err) => {
  console.error("MongoDB connection error:", err);
});

Terminal:

 MongoDB connection successful
 Mongoose connection state: 1

The Mongodb-site also shows in and output from/to my DB. So i feel like the connection is successful especially as it took a while to get the terminal logs to show a successful connection/a 1 there and that changing correlates with in-/output appearing on the mongodb-site. But test2
// running tests
2. “mongoose” should be connected to a database
// tests completed
is not fullfiled. Solution Link worked fine for all previous gitpod challenges.
Anything obvious i’m missing? Thanks for your help.
###Your project link(s)

solution: http://localhost:3000

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

I cant check this from localhost, so is this all the code in question?

Should be everything that i added/was asked for in the task. The myApp.js part could obviously be shorter without the tests. Does this Snapshot work?
https://gitpod.io#snapshot/dd75fb5d-6806-49b9-85eb-7b66fba20326

Now im confused :smiley: For the Snapshot i changed MONGO_URI in the .env file and took my username/the pw out of it so im not connected to my db anymore but just now both tests were successful

Well if it works it could just be a glitch, I was able to clone or run your code on my machine same problem, The hint led me to this information.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.