Using Positional Operator For Multiple Levels Of Subdocuments
I am using sub-documents in mongodb. With one level of sub-documents, I can update documents with Parent.findOneAndUpdate({ _id: parentId, 'children._id': childId }, { $set: {
Solution 1:
Positional Operator ($) only supports one level and also the first matching element. As a workaround what you can do is this,
$set: {
'children.$.grandchildren.0.name': name
}
I think this issue is more clearly explained here
Post a Comment for "Using Positional Operator For Multiple Levels Of Subdocuments"