start mongo db and write create collection in nodejs | nodejs tutorials

 write mongo db and conncec to server


var mongoose= require("mongoose");

mongoose.connect('mongodb://localhost:27017/mydatabase' ,
{
useNewUrlParser: true,
useUnifiedTopology: true
})
.then((res) => {
console.log(
'connected'
);
})
.catch((err) => {
console.log(
`not connected`,
err
);
});

ist start the mongo db server

then import the mongodb


connect to server

if it is connect it will print connect otherwise not connected


in below program 

connect to mongodb and if eror show this 

if open show this


var db = mongoose.connection;
db.on('error',console.error.bind(console,'connection error'));
db.on('open', function(){
console.log('connected');
});


No comments:

Post a Comment

create cartoon video using ai

  https://www.piclumen.com/ using this we can crate cartoon photos https://hailuoai.video/ its not free upto 1000 points we canuse it for fr...