This is the command
const filter = {
searchWord: req.body.searchWord,
result: { $elemMatch: { idMeal: req.body.mealData.idMeal } },
};
const update = { $set: { 'result.$.strMeal': req.body.mealData.strMeal } };
const returnData = { returnOriginal: false };
Meal.findOneAndUpdate(
filter,
update,
returnData,
function (err, foundMeal) {
res.json(foundMeal.result);
}
);
If I use the $ operator it does not update the respective field but the 2nd field, so it works as if I typed
'result.1.strMeal'
Instead of
'result.$.strMeal'
Is this a Mongoose problem or what is it caused by?