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

$inc can sometimes rename existing fields when they end in '0'

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • ALL

      Steps to reproduce:

      > db.test.foo.insert({"a":

      {"c0":1}

      , 'c':2})
      > db.test.foo.find(

      {"c":2}

      )
      { "_id" : ObjectId("4def775276aed51aaa0684d3"), "a" :

      { "c0" : 1 }

      , "c" : 2 }
      > db.test.foo.update(

      {"c":2}

      , {'$inc':{'a.b0':1}})
      > db.test.foo.find(

      {"c":2}

      )
      // So far, so good
      { "_id" : ObjectId("4def775276aed51aaa0684d3"), "a" :

      { "b0" : 1, "c0" : 1 }

      , "c" : 2 }

      //Things go off the rails. This should add a new field, 'c00'
      > db.test.foo.update(

      {"c":2}

      , {'$inc':{'a.c00':1}})
      > db.test.foo.find(

      {"c":2}

      )

      // Notice the 'c0' key has been changed to 'c00'. This should have added a new field.
      { "_id" : ObjectId("4def775276aed51aaa0684d3"), "a" :

      { "b0" : 1, "c00" : 2 }

      , "c" : 2 }

      // This works as expected.
      > db.test.foo.update(

      {"c":2}

      , {'$inc':{'a.cc':1}})
      > db.test.foo.find(

      {"c":2}

      )
      { "_id" : ObjectId("4def775276aed51aaa0684d3"), "a" :

      { "b0" : 1, "cc" : 1, "c00" : 2 }

      , "c" : 2 }
      >

            Assignee:
            Unassigned Unassigned
            Reporter:
            bernie@mongodb.com Bernie Hackett
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: