I have this structure and want to rename one particular field inside the array with many other fields.
{
"_id" : NumberLong(1),
"Data" : [
{
"Payload" : {
"Body" : {
"quantity" : 1,
"productname" : "ABC"
}
}
}
]
}
I want to rename the fieldname quantity to itemquantity.
I have tried something like this.
db.getCollection('test').updateMany(
{},
[{
$set: {
Body: {
$map: {
input: "$Data",
in: {
UnitInvoiced: "$$this.Payload.Body.quantity"
}
}
}
}
}]
)