I am following these tutorials as I wanted to start with MongoDB and the MERN stack:
Try this It seems like you are using MongoDB atlas
mongoose
.connect( uri, { useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology: true })
.then(() => console.log( 'Database Connected' ))
.catch(err => console.log( err ));
and go to your MongoDB Atlas
-> NetworkAccess
-> Edit
-> and add Current IP address
it works!!
Try this
mongoose.connect(uri, {
useNewUrlParser: true,
useCreateIndex: true,
useUnifiedTopology: true
}).then(res=>{
console.log("DB Connected!")
}).catch(err => {
console.log(Error, err.message);
})
I understood you error as I also faced it will trying to connect to mongoDB.
This error is simply popping up because your mongoDB local server failed to connect to remote server probably because you don't shut down the file correctly.
How to fix:
c:\program files\mongodb\server\4.2\bin
).That's it , your mongodb server is running again. You can check again in cmd prompt by typing same command.