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

Behavior of Mongo update is different in 2.4 vs 2.6

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Critical - P2 Critical - P2
    • None
    • 2.6.2
    • None
    • None
    • ALL
    • Hide

      run following in 2.4 vs 2.6 and see the difference. This is creating issue in our code due to upgrade.

      db.books.update(
      {_id:1234},
      {
      item: "XYZ123",
      stock: 10,
      info:

      { publisher: "2255", pages: 150 }

      ,
      tags: [ "baking", "cooking" ]
      },

      { upsert: true, multi: false}

      )

      In 2.4 if the document is missing then it is creating the following document.
      ---------------------------------------
      {
      "_id" : ObjectId("552eb41bb0af794da9287199"),
      "item" : "XYZ123",
      "stock" : 10.0,
      "info" :

      { "publisher" : "2255", "pages" : 150.0 }

      ,
      "tags" : ["baking", "cooking"]
      }

      In 2.6 it is creating the following in same condition
      ----------------------------------------------------------------
      {
      "_id" : 1234.0,
      "item" : "XYZ123",
      "stock" : 10.0,
      "info" :

      { "publisher" : "2255", "pages" : 150.0 }

      ,
      "tags" : ["baking", "cooking"]
      }

      Show
      run following in 2.4 vs 2.6 and see the difference. This is creating issue in our code due to upgrade. db.books.update( {_id:1234}, { item: "XYZ123", stock: 10, info: { publisher: "2255", pages: 150 } , tags: [ "baking", "cooking" ] }, { upsert: true, multi: false} ) In 2.4 if the document is missing then it is creating the following document. --------------------------------------- { "_id" : ObjectId("552eb41bb0af794da9287199"), "item" : "XYZ123", "stock" : 10.0, "info" : { "publisher" : "2255", "pages" : 150.0 } , "tags" : ["baking", "cooking"] } In 2.6 it is creating the following in same condition ---------------------------------------------------------------- { "_id" : 1234.0, "item" : "XYZ123", "stock" : 10.0, "info" : { "publisher" : "2255", "pages" : 150.0 } , "tags" : ["baking", "cooking"] }

    Description

      Behavior of Mongo update is different in 2.4 vs 2.6.

      In our case _id was null so in 2.4 it was creating multiple document and which was correct behavior. in 2.6 the behavior changed and the Id is becoming null which is creating nullpointer exception and later all upsert are only updating that document instead of inserting.

      Steps to Reproduce
      ------------------------------------
      try to run following in 2.4 vs 2.6 and see the difference. This is creating issue in our code due to upgrade.

      db.books.update(
      {_id:1234},
      {
      item: "XYZ123",
      stock: 10,
      info:

      { publisher: "2255", pages: 150 }

      ,
      tags: [ "baking", "cooking" ]
      },

      { upsert: true, multi: false}

      )

      In 2.4 if the document is missing then it is creating the following document.
      ---------------------------------------
      {
      "_id" : ObjectId("552eb41bb0af794da9287199"),
      "item" : "XYZ123",
      "stock" : 10.0,
      "info" :

      { "publisher" : "2255", "pages" : 150.0 }

      ,
      "tags" : ["baking", "cooking"]
      }

      In 2.6 it is creating the following in same condition
      ----------------------------------------------------------------
      {
      "_id" : 1234.0,
      "item" : "XYZ123",
      "stock" : 10.0,
      "info" :

      { "publisher" : "2255", "pages" : 150.0 }

      ,
      "tags" : ["baking", "cooking"]
      }

      Attachments

        Activity

          People

            Unassigned Unassigned
            rajeshks117 Rajesh Sharma
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: