FOR a given DOCUMENT, where i have a unique sub document, which i want to update ..
{
id:1,
a:[
{
id:2,
b:[
{
id:3,
c:[
{
id:4,
d:["x","y"]
},
{
id:5,
d:["p","q"]
}
]
},
{
id:13,
c:[
{
id:14,
d:["w","q"]
},
{
id:15,
d:["i","j"]
}
]
}
]
}
]
}
FOR this document you cannot update d to d:["x","y","z"] ;
PROPOSED change to update using PLACEMARKERS $as : $1 / $2 to the matched location rather $elemMatch
NOTE : this is the proposed change .. beeter ways could be provided.
db.coll.update({
id:1,
a:[
{
id:2,
$as:1
b:[
{
id:3,
c:[
{
id:4,
$as:2
}
]
}
]
}
]
},
{
$addToSet:{$2:{"d":["z"]}}
}
);
PLEASE SEE $elemMatch or any other operator doesn't work here ..
even if i have the unique path to my subdocument. Which matches a single element .. i cannot update.. this is the BIGGEST feature gap.