How to update the value of shopping and food for particular array element in mongo db ?
MongoDB Document :
{
"data": [
{
"_id": "5e131eb4ea0c191cdc06f96b",
"firstName": "Anirudh",
"lastName": "Singla",
"gender": "Male",
"username": "anirudhsingla8",
"email": "anirudhsingla8@gmail.com",
"password": "rj13sl1608",
"cards": [
{
"card_number": "1014220122322233",
"shopping": 0,
"food": 0
},
{
"card_number": "1014220122322234",
"shopping": 0,
"food": 0
}
}
]
}
I was trying to update the value in subelement of array like the current value of shopping for "card_number"="1014220122322234" is 0. but I want to update it according to user need.like if user enter 10 then it should be updated to 0+10=10, if it is 10 and user enter 16 then it should be updated to 10+16=26 like this. But I am not able to figure out query for this type of update on mongodb docs.