Tell us what’s happening:
I attempted this challenge on GitPod. My work managed to pass test 1, but I stucked at test 2. However, my code did not raised an error when inspecting.
const mongoose = require('mongoose');
mongoose.connect(process.env.MONGO_URI, {useNewUrlParser:true, useUnifiedTopology:true}, function(error){
if(error){
console.log(error);
}else{
console.log("Success");
}
});
###Your project link(s)
solution: https://3000-freecodecam-boilerplate-nqy2qgsrzry.ws-us117.gitpod.io
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.3 Safari/605.1.15
Challenge Information:
MongoDB and Mongoose - Install and Set Up Mongoose
I think you would need to chain your catch
to the connect()
to return an error: ```
mongoose.connect('mongodb://127.0.0.1:27017/test').
catch(error => handleError(error));
1 Like
Maybe delete the function(error)
and try:
const mongoose = require('mongoose');
mongoose.connect(process.env.MONGO_URI, {useNewUrlParser: true, useUnifiedTopology: true })
.then(() => console.log('Success'))
.catch((error) => console.log(error));
This should handle your error more effectively, especially if the inital connection fails for some reason.
Thank you so much^^ this works well for me.
lasjorg
February 10, 2025, 5:49pm
5
If the connect method doesn’t work with a callback, you may have updated the Mongoose dependency. I would revert to the initial version in the starting boilerplate to avoid other issues related to API changes (like methods removed).
1 Like