As I have installed mongodb package using:
npm install mongodb --save
on terminal and made a file connection.js. Code inside it is:
var mongodb = require('mongodb');
var MongoClient = mongodb.MongoClient;
var url = 'mongodb://127.0.0.1:27017/my_database_name';
MongoClient.connect(url, function (err, db) {
if (err) {
console.log('Unable to connect to the mongoDB server. Error:', err);
} else {
console.log('Connection established to', url);
db.close();
}
});
And running command:
C:\Users\upasana\Desktop\node>node connection.js
on terminal. The error that I am facing is:
Unable to connect to the mongoDB server. Error: { [MongoError:connection 0 to 127.0.0.1:27017 timed out]
name: 'MongoError',
message: 'connection 0 to 127.0.0.1:27017 timed out' }