Original Collection:
{
'name': 'apple',
'total': 20,
'baskets': [
{
'name': 'basket_green',
'total': 0
}
]
}
How to update ‘baskets’ array with a new element which would take ‘total’ from object.
So the resulting collection should look like:
{
'name': 'apple',
'total': 20,
'baskets': [
{
'name': 'basket_green',
'total': 20
}
]
}
MongoDB Server 5.0
I tried updating with $set operator with positional operator ‘$’. But it is not working as expected. The literal string ‘$total’ is getting set to array element ‘basket_green’.