I am trying to find whether my collection has a record with profilename = john and if exists I return status success if else I return fail but in my case, it is returning success for both cases.I am new to node and mongo can any one help me.
My function,
exports.searchprofilename = function (req, res) {
var params = req.params;console.log(req.params.id);
var record= db.collection('profile');
record.find({profilename:params.id}, (err, result) => {
if (err){ return console.log(err)
}
if(!result){
data = {status:'success'};
} else{
data = {status:'profile name already exists'};
}
res.send(data);
});
};