[SERVER-2016] $pull with $elemMatch and $in does not work Created: 27/Oct/10  Updated: 09/Jul/16  Resolved: 17/Sep/13

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: 1.7.1
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Tony Hannan Assignee: Unassigned
Resolution: Done Votes: 4
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Wed Oct 27 08:59:28 db version v1.7.2-pre-, pdfile version 4.5
Wed Oct 27 08:59:28 git version: 5b1d4d2b75b356b5fb131d702699bca35cd44e7b


Issue Links:
Related
related to SERVER-3988 should regex matching work with $pull... Closed
Operating System: ALL
Participants:

 Description   

"db.bar.update({}, {$pull: {y: {$elemMatch: {a: 2}}}}, false, true)" works, but
"db.bar.update({}, {$pull: {y: {$elemMatch: {a: {$in: [2,3]}}}}}, false, true)" does not.

Sample document:
{x: 0, y: [

{a:1}

,

{a:2}

]}



 Comments   
Comment by Andrew Morrow (Inactive) [ 17/Sep/13 ]

Hi Tony -

The argument to $pull is already applied to each element of the target array, so using $elemMatch is redundant in the update context. The workaround, as you suggested in your comment, is to just not use $elemMatch, and $pull will iterate over the array automatically.

I'm going to close this as 'works as designed'. Please feel free to re-open if the above workaround is insufficient for you.

We will also update the documentation to reflect that a top-level $elemMatch should not be provided to $pull.

Thanks,
Andrew

Comment by Tony Hannan [ 27/Oct/10 ]

But "db.bar.update({}, {$pull: {y: {a: {$in: [2,3]}}}}, false, true)" does work.

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