I'm trying to delete the subobject 'apples' from my documents and update the 'fruitInventory' property, decrease by the amount of apples.
I'm confused on how to proceed, should I use dot notation or do a full text search for apples? I don't know if this matters but you can assume apples will always be in field 1.
// Document 1
{
"1": {
"apples": 3,
"fruitInventory": 21,
"oranges": 12,
"kiwis": 3,
"lemons": 3
},
"2": {
"bananas": 4,
"fruitInventory": 12,
"oranges": 8,
},
"_id": "1"
}
// Document 2
{
"1": {
"apples": 5,
"fruitInventory": 10,
"oranges": 2,
"pears": 3
},
"2": {
"bananas": 4,
"fruitInventory": 6,
"cherries": 2,
},
"_id": "2"
}
Result should be like this:
// Document 1
{
"1": {
"fruitInventory": 18,
"oranges": 12,
"kiwis": 3,
"lemons": "3"
},
"2": {
"bananas": 4,
"fruitInventory": 12,
"oranges": 8,
},
"_id": "1"
}
// Document 2
{
"1": {
"fruitInventory": 5,
"oranges": "2",
"pears": "3"
},
"2": {
"bananas": 4,
"fruitInventory": 6,
"cherries": 2,
},
"_id": "2"
}
Thanks in advance for your help.