I have this record in MongoDb, and am using the native API:
{
"_children" : {
"addressesR" : [
{
"id" : ObjectId("530eea01071bd1a53065c1a6"),
"personId" : ObjectId("530eea01071bd1a53065c1a4"),
"street" : "ivermey",
"city" : "perth",
"_children" : {
}
},
{
"_children" : {
"configId" : {
"a" : {
"_children" : [
{
"b" : 10
},
{
"b" : 20
}
]
}
}
},
"city" : "perth",
"configId" : ObjectId("530eea01071bd1a53065c1a3"),
"id" : ObjectId("530eea01071bd1a53065c1a5"),
"personId" : ObjectId("530eea01071bd1a53065c1a4"),
"street" : "bitton"
}
],
}
}
I need to update, in one query, that nested 'b' to 30. I can find the record:
db.peopleR.find( { '_children.addressesR._children.configId.a._children.b': 20 } );
But I am having a hard time finding a way to update that particular value.
I am trying:
db.peopleR.update( { '_children.addressesR._children.configId.a._children.b': 20 }, { $set: { '_children.addressesR.$._children.configId.a.$._children.b': 30 } } )
But I am getting:
Cannot apply the positional operator without a corresponding query field containing an array.
Now, considering that for other constraints I absolutely need to update just 'b', is there a way for me to do it? Or, is it impossible to use the $ operand twice? ( that is, I can only update the inner part of an object if it's only 1 level down?)