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

React -1 ( react with ravenndra kanchi)

 react with tool chanis 45 to 50 sessions core  after 50 sessions -> some tooll chains == react with type script mern stackaplication in ...