I have created one sample application for connection of mongodb and nodejs. I got error like MongoError: there are no users authenticated
after that I have added username and password to the mongodb connection string like "mongodb://root:root@localhost:27017/marankings"
so authentication eror has gone and it gives me new error like
Buffer.from('n=', 'utf8'), ^
TypeError: utf8 is not a function at Function.from (native) at Function.from (native)
Please guide me on this , I am stuck here.
This is my code
connectToServer: function(callback) {
MongoClient.connect("mongodb://root:root@localhost:27017/marankings", function(err, db) {
//db = db;
var dbcon=db.db("marankings");
console.log("this is connected db"+_db);
var myobj = { name: "Akshay Champavat", address: "[email protected]" };
dbcon.collection("users").insertOne(myobj, function(err, res) {
if (err) throw err;
console.log("1 document inserted");
dbcon.close();
});
return callback(err);
});
},
Please help , Thanks in advance !!!
callbacktoo early. Have you try puting it in theinsertOnecallback? What does the db look like, is your user really inserted? Also please show us how you retrieve your user.