[SERVER-2092] Unexpected matching behaviour for current $pull with $elemMatch syntax Created: 11/Nov/10  Updated: 17/Mar/11  Resolved: 13/Nov/10

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 1.6.3
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Remon van Vliet Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

All


Backwards Compatibility: Major Change
Participants:

 Description   

Currently the syntax for the $pull operand is confusing and conflicts with normal behaviour of $elemMatch.

Given document :

{"somearray" : [

{ "a" : 1, "b" : 1, "c" : 1 }

,

{ "a" : 1, "b" : 1 }

,

{ "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.



 Comments   
Comment by Remon van Vliet [ 15/Nov/10 ]

I'm sure it is, but then what does the specifically documented $elemMatch version of $pull add? And how does one pull just the

{a:1, b:1}

element as I mentioned. I'm sure the way it works now is intended. The issue is reported because the way it's intended to work isn't consistent with the syntax of other parts of the query language.

Comment by Eliot Horowitz (Inactive) [ 13/Nov/10 ]

$pull is supposed to be a partial match.

Comment by Remon van Vliet [ 11/Nov/10 ]

Sorry, the comment on EXPECTED BEHAVIOUR of case 1 should be "partial match on first item, so pull that and the second item"

Generated at Thu Feb 08 02:58:57 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.