[SERVER-9116] $pull operation does not work with $each Created: 25/Mar/13  Updated: 10/Dec/14  Resolved: 25/Mar/13

Status: Closed
Project: Core Server
Component/s: Internal Code
Affects Version/s: 2.4.1
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Anatoly Borisov Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-9121 Error on invalid $pull: "{$pull: {fla... Closed
Operating System: ALL
Steps To Reproduce:

Copy-paste from console:

> db.test.save({_id : 1})
> db.test.find()

{ "_id" : 1 }

> db.test.update({_id : 1}, {$addToSet: {flags : {$each : [1,2,3,4,5,6]}}})
> db.test.find()

{ "_id" : 1, "flags" : [ 1, 2, 3, 4, 5, 6 ] }

> db.test.update({_id : 1}, {$pull: {flags : {$each : [1,2,3]}}})
> db.test.find()

{ "_id" : 1, "flags" : [ 1, 2, 3, 4, 5, 6 ] }
Participants:

 Description   

$addToSet with $each works OK, but $pull does not



 Comments   
Comment by Anatoly Borisov [ 25/Mar/13 ]

Then it should raise a syntax error or something, I guess

Comment by Scott Hernandez (Inactive) [ 25/Mar/13 ]

This is not a bug, and is expected behavior. The push syntax is different than the pull syntax because the latter is a query.

$pull takes a query so there is no need for it to take a $each + array.
http://docs.mongodb.org/manual/reference/operator/pull/

There is a $pullAll if you want but that is just for scalars (not a query). It is just a convienience methods at this point since you can craft an $in/$or query using $pull.
http://docs.mongodb.org/manual/reference/operator/pullAll/

In your example you can use $in to replace $each and it will work as you want.

Generated at Thu Feb 08 03:19:26 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.