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

Possible to end up with an empty string property which can lead to silent troubles

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.4.6
    • Component/s: Write Ops
    • Labels:
      None
    • ALL
    • Hide

      To get a nameless property from shell:

      db.testGuy.insert({Name: "Test1"})
      db.testGuy.update({Name: "Test1"}, {$inc: {"TestObject..Value": 1}})
      db.testGuy.findOne({Name: "Test1"})
      {
              "Name" : "Test1",
              "TestObject" : {
                      "" : {
                              "Value" : 1
                      }
              },
              "_id" : ObjectId("52f93e1be856377627267033")
      }
      

      Yikes! Now what happens if I try to mess around with TestObject?

      db.testGuy.update({Name: "Test1"}, {$inc: "TestObject.TestProperty.Value": 1}})
      db.testGuy.findOne({Name: "Test1"})
      {
              "Name" : "Test1",
              "TestObject" : {
                      "" : {
                              "Value" : 1
                      }
              },
              "_id" : ObjectId("52f93e1be856377627267033")
      }
      db.testGuy.update({Name: "Test1"}, {$inc: {VeryCoolValue: 1, "TestObject.AnotherValue": 1}})
      {
              "Name" : "Test1",
              "TestObject" : {
                      "" : {
                              "Value" : 1
                      }
              },
              "VeryCoolValue" : 1,
              "_id" : ObjectId("52f93e1be856377627267033")
      }
      

      That last one shows the danger of this kind of situation: the updates partially complete and report success even though half of my update actually failed.

      Show
      To get a nameless property from shell: db.testGuy.insert({Name: "Test1" }) db.testGuy.update({Name: "Test1" }, {$inc: { "TestObject..Value" : 1}}) db.testGuy.findOne({Name: "Test1" }) { "Name" : "Test1" , "TestObject" : { "" : { "Value" : 1 } }, "_id" : ObjectId( "52f93e1be856377627267033" ) } Yikes! Now what happens if I try to mess around with TestObject? db.testGuy.update({Name: "Test1" }, {$inc: "TestObject.TestProperty.Value" : 1}}) db.testGuy.findOne({Name: "Test1" }) { "Name" : "Test1" , "TestObject" : { "" : { "Value" : 1 } }, "_id" : ObjectId( "52f93e1be856377627267033" ) } db.testGuy.update({Name: "Test1" }, {$inc: {VeryCoolValue: 1, "TestObject.AnotherValue" : 1}}) { "Name" : "Test1" , "TestObject" : { "" : { "Value" : 1 } }, "VeryCoolValue" : 1, "_id" : ObjectId( "52f93e1be856377627267033" ) } That last one shows the danger of this kind of situation: the updates partially complete and report success even though half of my update actually failed.

      Several operations ($set and $inc tested, there may be others) can create a nameless property which becomes difficult to remove and causes updates to partially and silently fail.

            Assignee:
            Unassigned Unassigned
            Reporter:
            jacqueswaller Jacques Waller
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: