I have a database in mongodb for restaurants. Sample database is as follows.
{
"restaurantId":"1",
"menu":
{
"menuCategory":
[
{
"menuCategoryId":"12"
"menuItems":
[
{
"menuId":"123",
"likesCount":0
},
{
"menuId":"1234",
"likesCount":0
}
]
},
{
"menuCategoryId":"1290"
"menuItems":
[
{
"menuId":"2222",
"likesCount":0
},
{
"menuId":"3333",
"likesCount":0
}
]
}
]
}
}
In this document, I have to either increase or decrease the likes count against the menuId and restaurantId which is received in yii2. I am not able to find the likes count for the particular menuId in the restaurant to update it.
I tried the following query to update the likesCount.
db.restaurants.update({$and:[{"restaurantId":"1"},{"menu.menuCategory.menu.menuId":"123"}]}, {$set:{"likesCount":5}})