for the following structure, I am trying to update the first array item under options to be ["milk", 1]:
{
options:[["milk", 0],
["chocolate", 0],
["others", 0]],
timestamp:"2017-09-26T14:42:49.359Z"
title:"shopping list"
username:"a"
}
this is the mongoose snippet I use.
router.put('/',(req,res) => {
let {_id, value, option} = req.body;
eventModel.findOneAndUpdate(
{_id:_id, options: [option, value]},
{ $set: {"options.$": [option, value + 1]}},
function(err){
if(err){
res.status(400).json({ error: err });
}
console.log("event updated");
});
});
I always get the "event updated" with no errors but the item does not get updated, any help is appreciated. Thank you