-
Type: Improvement
-
Resolution: Done
-
Priority: Minor - P4
-
None
-
Affects Version/s: 1.6.3
-
Component/s: Querying
-
None
-
Environment:All
-
Major Change
Currently the syntax for the $pull operand is confusing and conflicts with normal behaviour of $elemMatch.
Given document :
{"somearray" : [
,
,
{ "a" : 1 }] }
The current and expected behaviour of using $elemMatch or omitting it for an update to pull out an element is as follows :
UPDATE: db.test.update({}, {$pull : {somearray : {$elemMatch : {a:1, b:1}}}})
EXPECTED BEHAVIOUR : partial match on first item, so pull that
CURRENT BEHAVIOUR : has no effect
UPDATE: db.test.update({}, {$pull : {somearray :
{a:1, b:1}}})
EXPECTED BEHAVIOUR : exact match on second item, so pull that
CURRENT BEHAVIOUR : removes item 1 and 2, so it's partial matching which is the usage pattern for the $elemMatch case
The end result is both behaviour that's less than intuitive and presents the problem i'm currently facing with our migration to mongo : How do I remove just the second item with exact/full document matching?
If this isn't a bug the $elemMatch example should be removed from the docs and the docs itself should elaborate on $pull only supporting partial matching. If it is a bug however it does present the problem if it being impossible to fix without breaking backward compatibility.