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

document field (key) magically changed by mongodb

    • Linux

      Please refer to the following code:

      // on mongodb 1.8.x

      use test_db
      db.revs.save({})
      doc = db.revs.findOne()
      db.revs.update(

      { _id : doc._id }

      , { $inc :

      { "versions.2_01" : 1 }

      } )

      db.revs.findOne()
      {
      "_id" : ObjectId("4f699826d603f81fdec82a62"),
      "versions" :

      { "2_01" : 1 }

      }

      db.revs.update(

      { _id : doc._id }

      , { $inc :

      { "versions.2_1" : 1 }

      } )

      db.revs.findOne()
      {
      "_id" : ObjectId("4f699826d603f81fdec82a62"),
      "versions" :

      { "2_1" : 2 // key magically changed to 2_1 !!! }

      }

      db.revs.update(

      { _id : doc._id }

      , { $inc :

      { "versions.2_01" : 1 , "01" : 1 }

      } )
      db.revs.findOne()
      {
      "_id" : ObjectId("4f699826d603f81fdec82a62"),
      "versions" :

      { "2_01" : 3 }

      ,
      "01" : 1
      }

      db.revs.update(

      { _id : doc._id }

      , { $inc :

      { "versions.2_01" : 1 , "1" : 1 }

      } )
      db.revs.findOne()
      {
      "_id" : ObjectId("4f699826d603f81fdec82a62"),
      "versions" :

      { "2_01" : 4 // key magically changed back to 2_01 !!! }

      ,
      "1" : 2 // key magically changed to 1 !!!
      }

      //==========================================================

      // on mongodb 2.0.x

      use test_db
      db.revs.save({})
      doc = db.revs.findOne()
      db.revs.update(

      { _id : doc._id }

      , { $inc :

      { "versions.2_01" : 1 }

      } )

      db.revs.findOne()
      {
      "_id" : ObjectId("4f69a044e5ce33194e694fdc"),
      "versions" :

      { "2_01" : 1 }

      }

      db.revs.update(

      { _id : doc._id }

      , { $inc :

      { "versions.2_1" : 1 }

      } )

      db.revs.findOne()
      {
      "_id" : ObjectId("4f69a044e5ce33194e694fdc"),
      "versions" :

      { "2_1" : 1, "2_01" : 1 // nice, seems that this kind of bug fixed in 2.0.x }

      }

      db.revs.update(

      { _id : doc._id }

      , { $inc :

      { "versions.2_01" : 1 , "01" : 1 }

      } )
      db.revs.findOne()
      {
      "_id" : ObjectId("4f69a044e5ce33194e694fdc"),
      "versions" :

      { "2_1" : 1, "2_01" : 2 }

      ,
      "01" : 1
      }

      db.revs.update(

      { _id : doc._id }

      , { $inc :

      { "versions.2_01" : 1 , "1" : 1 }

      } )
      db.revs.findOne()
      {
      "_id" : ObjectId("4f69a044e5ce33194e694fdc"),
      "versions" :

      { "2_1" : 1, "2_01" : 3 // nice, seems that this kind of bug (*_0x) fixed in 2.0.x }

      ,
      "1" : 2 // key magically changed to 01 agin in 2.0.x, this kind of bug (0x) still not fully fixed !!!
      }

            Assignee:
            aaron Aaron Staple
            Reporter:
            stonegao Stone, Gao
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: