Cannot connect to mongodb

I was having issue related to saving documents , I removed everything , copied env file code from previous project which is working but still
is giving 0 means not connected
please have a look at the code , I removed everything but still its not connecting

Hey there, i have taken a look at your code and it seems updating the packages will help you out, you can also use this code snippet to check for a successful connection without errors.

mongoose.connect(process.env.MONGO_URI,{useNewUrlParser: true, useUnifiedTopology: true}, (err, res)=>{
    console.log(err + "error" + err )
    console.log("successful database connection");

The connection state is 2, bu t i believe it will load your db.


its working now, I tried clearning all the code and searched everywhere but nothing worked .this made me cry thanks a lot .the frustration was building up :sob: :sob:

1 Like

I know how it feels.
a tip however is when dealing with the backend, always try and make sure you handle the errors like how i have done using a callback function, it reduces the risk of unknown errors.

1 Like

Hours, hours, hours!
This part of the curriculum is very sketchy. There were just too many balls in the air at the same time and I know, it was in the EM, true, I’ll be a good girl from now on, but nevertheless this was a hard one.

Thanks a million,