I am trying to update the values in a mongodb collection using a mongoose model but i cant seem to make it work the way i want. I would like the value of a particular field to be a multiple of an updated field.
var id = req.user._id
Model.findById({_id: id},function(err,doc){
if(err){
console.log(err)//handle error
)//handle error
}else{
//update file
doc.field1 = req.body.formInput;
doc.field2 = {$multiply: [doc.field1, 2]};
doc.save();
};
});
If anyone can help please, I don't know the right way to do this and its breaking my app. Please help a brother.
via Blaze4dem
No comments:
Post a Comment