Tuesday, July 2, 2019

ReferenceError: MongoClient is not defined

Hi Guys ,

In this blog I will share information related to error : ReferenceError: MongoClient is not defined .


This error is related to the node.js code which is trying to connect to the database . To fix this check the following lines of code highlighted in yellow  . You need to make sure module mongodb is imported and the MongoClient is referenced using the variable .






var mongo = require('mongodb');
var url = "mongodb://localhost:27017/qanda";
mongo.MongoClient.connect(url, function(err, db) {
if (err) throw err;
console.log("Database created!");
db.close();
});
Please make changes to the code and retest . Hope this will help you in resolving this issue .

No comments:

Post a Comment

ec2-user@ec2 Permission denied