[SERVER-19303] $pull is pulling only in last occurence of query,db.getCollection('sid').update({_id:1},{$pull:{array1:"sid"},$pull:{array2:"kp"}}) Created: 07/Jul/15  Updated: 07/Jul/15  Resolved: 07/Jul/15

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

Type: Bug Priority: Major - P3
Reporter: siddharth jain Assignee: Sam Kleinman (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to DOCS-5792 Add examples of more complex $pull op... Closed
Operating System: ALL
Participants:

 Description   

Pull operation works only on one array even called twice over a document

Over this document

{ "_id" : 1, "array1" : [ "sid", "yd" ], "array2" : [ "ram", "kp" ] }

I have run following query

db.getCollection('sid').update({_id:1},{$pull:

{array1:"sid"}

,$pull:{array2:"kp"}})

result:

{ "_id" : 1, "array1" : [ "sid", "yd" ], "array2" : [ "ram" ] }

 Comments   
Comment by Sam Kleinman (Inactive) [ 07/Jul/15 ]

I believe that one of the following operation will accomplish the update that you're looking for. I've opened DOCS-5792 to track adding additional examples to the documentation.

db.getCollection("sid").update({_id: 1}, {$pull: { "array1": {$in: ["sid", "yd"]}, "array2": "kp" }})
db.getCollection("sid").update({_id: 1}, {$pull: { "array1": "sid", "array2": "kp" }})

Be aware that JSON documents (as in the shell,) and BSON documents as translated by most drivers require that all keys in a document must be unique (i.e. $pull must appear only once in the update specification.)

Cheers,
sam

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