Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-43289

$inc behaves differently for missing vs null fields

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: Backlog
    • Component/s: Write Ops
    • Labels:
      None

      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"
              }
      })
      

        Attachments

          Activity

            People

            Assignee:
            backlog-server-query Backlog - Query Team
            Reporter:
            redbeard0531 Mathias Stearn
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

              Dates

              Created:
              Updated: