Connect to MongoDb using mongoose in NODE js

Here is the way, to connect mongodb in NODE js using mongoose module

// first of all require mongoose NODE module
var mongoose = require('mongoose');

// then connect to local mongodb database
var db = mongoose.connect('mongodb://127.0.0.1:27017/test');

//And finally attach a listener to connected event if want to check status/ other
mongoose.connection.once('connected', function() {
console.log("Database Connected")
});

Comments

Popular posts from this blog

What is MQTT protocol & its use

What the hack is Call, bind & apply

What is Provider in Angular Js?