I have this data structure in my MongoDB database:
"menu": [
{
"dishCategory":"61e6089f209b802518e2b4a4",
"dishMeals": [
{
"dishMealName": "Burger King",
"dishMealIngredients": "Burger lepinja, bbq sos, berlin sos, zelena"
"dishMealPrice": 5
}
]
}
]
How do I push a new object inside dishMeals in exact dishCategory ( I am providing dishCategoryId
, newDish
object and _id of restaurant through req.body) I've tried this but nothing is changing:
await Restaurants.updateOne(
{
'_id' : _id,
'menu.dishCategory' : dishCategoryId
},
{
$push : {
'menu.$.dishMeals' : newDish
}
}
);