[SERVER-43289] $inc behaves differently for missing vs null fields Created: 11/Sep/19  Updated: 06/Dec/22

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

Type: Improvement Priority: Major - P3
Reporter: Mathias Stearn Assignee: Backlog - Query Optimization
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query Optimization
Participants:

 Description   

We usually try to treat null and missing fields mostly the same, so this seems like surprising behavior.

MongoDB Enterprise asdf:PRIMARY> db.foo.insert({_id: 1, b: null})
WriteResult({ "nInserted" : 1 })
MongoDB Enterprise asdf:PRIMARY> db.foo.update({_id: 1}, {$inc: {a: 1}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
MongoDB Enterprise asdf:PRIMARY> db.foo.update({_id: 1}, {$inc: {b: 1}})
WriteResult({
        "nMatched" : 0,
        "nUpserted" : 0,
        "nModified" : 0,
        "writeError" : {
                "code" : 14,
                "errmsg" : "Cannot apply $inc to a value of non-numeric type. {_id: 1.0} has the field 'b' of non-numeric type null"
        }
})


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