Reputation: 9
i just finished learning how to implement crud using mangodb and am trying to connect node.js to mongodb. when i use 'mongodb://localhost:27017' as my url m terminal show an error (in the picture.) and when i use 'mongodb://127.0.0.1:27017'as my url, the terminal just hook please how can i solve this. The first image is where the terminal refuse to responsed image with terminal hook The second image is where the terminal showed an error image with error
well with my code i was expecting Connected to MongoDB server... in my console
Upvotes: 0
Views: 42
Reputation: 1440
I hope this answer will help you to find a solution.
const mongoose = require('mongoose');
// mongoose.connect('mongodb://username:password@localhost:27017/your db name')
mongoose.connect('mongodb://127.0.0.1:27017/student')
.then(()=> console.log('Connected to DB'))
.catch((err)=> console.log(err));
Upvotes: 0