I've searched across the site of course, but it seems that there is confusing terminology regarding what is a "subdocument"...
Imagine we have two collections (Pages and Items) with the following schemas:
Item:
_id: ObjectId
name: String
Page:
_id: ObjectId
titles: [ {value: String} ]
items: [ Relationship <Item>, many: true ]
If I try to update "titles" sub-array - everything works fine:
db.pages.update({_id: ...}, { $set: {"titles.0.value": "x"} });
But if I try to update "items" sub-documents-array - it fails:
db.pages.update({_id: ...}, { $set: {"items.0.name": "x"} });
The error is returned:
"cannot use the part (0 of items.0.name) to traverse the element"
If I try to replace "0" with a "$" like this:
db.pages.update({_id: ...}, { $set: {"items.$.name": "x"} });
Another error is returned:
"The positional operator did not find the match needed from the query. Unexpanded update: items.$.name"
How to correctly update the value inside the related subdocument?