Facing issue while trying to update an element within an array of sub document in Mongo. If I consider the following document in the collection "resource"
{
"_id": 1,
"resources": [
{
"resource_id": 1,
"resource_list": ["item1","item2"]
},
{
"resource_id": 2,
"resource_list": ["item4","item3"]
}
]
}
I want to update "item4"
with some other value like "item5"
for "resource_id" = 2
The following statement gave me an error : Cannot apply the positional operator without a corresponding query field containing an array.
db.resource.update({"resources.resource_id": 2, "resources.resource_list": "item4"}, {$set: {"resources.$.resource_list.$": "item5"}})
Any help on this will be highly appreciated.