I have a collection "user" as follows:
{
_id: "123",
"address": {
"contact1":{
"cell":"98765412345"
},
"contact2":{
"cell":"98765412346"
}
}
}
I want to rename the field 'cell' to 'mobile' in all the nested objects contact1, contact2 and so on.
The following query works:
db.user.update({},{$rename:{'address.contact1.cell':'address.contact1.mobile'}})
I would ideally want all the nested objects to be updated. So I tried
db.user.update({},{$rename:{'address.$.cell':'address.$.mobile'}})
and this doesn't work. I searched for similar issues and all of them has nested arrays instead of maps (as in my case) and the answer that I got is that $rename doesn't work on nested arrays. I would want to know if its possible using a query instead of a script