Details
-
Bug
-
Resolution: Duplicate
-
Major - P3
-
None
-
3.4.1, 3.4.7, 3.5.12
-
None
-
ALL
Description
Consider a simple collection with a single document, build this way :
("a" and "a2" fields are used to demonstrate the update behavior below)
db.mongo.insert(
|
{
|
"a":[NumberInt(123), NumberInt(456), NumberInt(789)], |
"a2": NumberInt(456), |
"b":{ |
"c":[ |
{"d":NumberInt(10), "e":NumberInt(20)}, |
{"d":NumberInt(10), "e":NumberInt(21)}, |
{"d":NumberInt(10), "e":NumberInt(22)}, |
{"d":NumberInt(10), "e":NumberInt(23)}, |
{"d":NumberInt(10), "e":NumberInt(24)}, |
{"d":NumberInt(11), "e":NumberInt(25)}, |
{"d":NumberInt(11), "e":NumberInt(26)}, |
{"d":NumberInt(11), "e":NumberInt(27)}, |
]
|
}
|
}
|
);
|
My goal is to update array b.c and add elements to a set where d = 10 and e = 24, only for document where a = 456.
This first query does not work : it updates the element in array b.c with the position of "456" in the a array ( = the second element), even with the $elemMatch on b.c.
db.mongo.update(
|
{
|
"a": NumberInt(456), |
"b.c": { |
"$elemMatch": { |
"d": NumberInt(10), |
"e": NumberInt(24) |
}
|
}
|
},
|
{
|
"$addToSet":{ |
"b.c.$.f":{"x":NumberInt(1), "y":NumberInt(2)} |
}
|
}
|
);
|
This second query does work : it updates the correct element in array because a2 is not an array. This issue being, I need a to be an array and hold several values.
db.mongo.update(
|
{
|
"a2": NumberInt(456), |
"b.c": { |
"$elemMatch": { |
"d": NumberInt(10), |
"e": NumberInt(24) |
}
|
}
|
},
|
{
|
"$addToSet":{ |
"b.c.$.f":{"x":NumberInt(1), "y":NumberInt(2)} |
}
|
}
|
);
|
I have tried to change the order of the conditions in the query part, but this does not change the behavior.
Any help (or even better, a fix..) would be greatly appreciated.
Tested on 3.4.1, 3.4.7 and 3.5.12 (to see if the changes in SERVER-831 would fix it.
Attachments
Issue Links
- duplicates
-
SERVER-18500 Resolve ambiguity of positional projections with multiple implicit array traversal predicates in certain cases
-
- Backlog
-
- is related to
-
SERVER-27089 Extend the update subsystem to support more expressive updates to array fields
-
- Closed
-