[SERVER-12847] v2.6.0-rc0 update $pull - changed and inconsistent behaviour Created: 23/Feb/14  Updated: 10/Dec/14  Resolved: 25/Feb/14

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

Type: Improvement Priority: Minor - P4
Reporter: Roman Kuzmin Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:

 Description   

The steps:

Step 1.
Add an object {_id : 1, a : [1, 2]} to the empty collection test:

> db.test.drop()
> db.test.insert({_id : 1, a : [1, 2]})

Step 2.
Let's try to pull from a[-2], i.e. from non existent data. This is nonsense perhaps but it changed behaviour.

> db.test.update({_id : 1}, {$pull : {"a.-2" : 1}})
WriteResult({
        "nMatched" : 0,
        "nUpserted" : 0,
        "nModified" : 0,
        "writeError" : {
                "code" : 16837,
                "errmsg" : "cannot use the part (a of a.-2) to traverse the element ({a: [ 1.0, 2.0 ]})"
        }
})

The above pull fails and data are not changed. In v2.4.9 this nonsense pull was silently ignored. New behaviour is better, more likely.

Step 3.
Now let's pop from a[3], i.e. also from non existent data.

> db.test.update({_id : 1}, {$pull : {"a.3" : 1}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 0 })

Unlike step 2, the step 3 does not fail. It is silently ignored. I think it would be better if the results are consistent, i.e. both fails or ignored. Personally, failures are more expected and informative.

P.S. Related or not, but $pop also changed, probably incorrectly, see the similar steps in
https://jira.mongodb.org/browse/SERVER-12846



 Comments   
Comment by Daniel Pasette (Inactive) [ 25/Feb/14 ]

The two cases are a bit different, the first case is an illegal identifier for an array, and thus there is an error. The second case is consistent with 2.4.9, and is akin to querying for data that does not exist. It correctly does not modify the document and does not error out.

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