I am trying to update a data inside the MongoDB database . I am using findByIdAndUpdate
function to do this , but a duplicate data gets inserted into the database . This is happening every time I am trying to update the data . Also used db.collection.update()
but the same thing is happening .
I have also used
findByIdAndUpdate(userId, { $set: {isPrime:true} },function(err,data)
It is also not working .
Code :
router.get('/getPremium',function(req,res){
if(req.isAuthenticated()){
var userId = req.user.id ;
console.log(req.user);
console.log(req.user._id);
User.findByIdAndUpdate(userId,{isPrime:true},function(err,data){
if(err) throw err;
})
res.redirect('/');
}else{
res.redirect('/');
}
})
I have also found answer to this findOneAndUpdate causing duplication problem but did not found it useful .
Any help regarding this will be helpful for me .