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

server laravel application

 asset_url = domain/public chmod -R 755 public/admin/ composer dump-autoload get the application from hostinger