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

Casted type-change updates are discarded

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Duplicate
    • Affects Version/s: 3.2.1
    • Fix Version/s: None
    • Component/s: Shell
    • Labels:
      None
    • Operating System:
      ALL
    • Steps To Reproduce:
      Hide

      A simple example:

      // insert a document into a new table; number is interpreted as a double
      db.example.insert({"foo": 1})
      //--> WriteResult({ "nInserted" : 1 })
       
      // good so far
      db.example.find()
      //--> { "_id" : ObjectId("56b4c6dcbfa50a533004158a"), "foo" : 1 }
       
      // confirm the field is of type double
      // ref: https://docs.mongodb.org/manual/reference/operator/query/type
      db.example.count({"foo": {"$type": 1}})
      //--> 1
       
      // attempt to update field from double to integer; fails
      db.example.update({"foo": {"$type": 1}}, {"$set": {"foo": NumberInt(1) }})
      //--> WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 0 })
       
      // doc still has a double
      db.example.count({"foo": {"$type": 1}})
      //--> 1
       
      // update field from double to integer of a different value; succeeds
      db.example.update({"foo": {"$type": 1}}, {"$set": {"foo": NumberInt(2) }})
      // WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
       
      // doc no longer has a double
      db.example.count({"foo": {"$type": 1}})
      //--> 0
       
      // confirm doc now has an int
      db.example.count({"foo": {"$type": 16}})
      //--> 1
      

      Show
      A simple example: // insert a document into a new table; number is interpreted as a double db.example.insert({"foo": 1}) //--> WriteResult({ "nInserted" : 1 })   // good so far db.example.find() //--> { "_id" : ObjectId("56b4c6dcbfa50a533004158a"), "foo" : 1 }   // confirm the field is of type double // ref: https://docs.mongodb.org/manual/reference/operator/query/type db.example.count({"foo": {"$type": 1}}) //--> 1   // attempt to update field from double to integer; fails db.example.update({"foo": {"$type": 1}}, {"$set": {"foo": NumberInt(1) }}) //--> WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 0 })   // doc still has a double db.example.count({"foo": {"$type": 1}}) //--> 1   // update field from double to integer of a different value; succeeds db.example.update({"foo": {"$type": 1}}, {"$set": {"foo": NumberInt(2) }}) // WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })   // doc no longer has a double db.example.count({"foo": {"$type": 1}}) //--> 0   // confirm doc now has an int db.example.count({"foo": {"$type": 16}}) //--> 1

      Description

      When attempting to update a document by changing the type of a field, that update appears to be discarded if the result is casted-equivalent. So far, I've observed this behavior when attempting to replace a double with an int of the same value.

      Combined with SERVER-22489, this became an irritating problem; the only workaround I have so far is to update with some erroneous value, then update a second time to fix it.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                7 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: