I am facing a issue while connecting to Mongodb using mongoose.
The problem is when i am offline it shows connection failed to localhost:27017
but when i am online it connects successfully.
The code for reference is below:
mongoose.connect('mongodb://localhost/database');
var db = mongoose.connection;
db.on('error', function (err) {
console.log('connection error', err);
});
db.once('open', function () {
console.log('connected.');
});
And here is the screenshot of both the situation.
Do I need to make some configuration in my system to make it work or It just work this way.