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

Failed to apply an update with multiple conditions in an array

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Querying, Write Ops
    • ALL

      db.bug.save({
      _id:1,
      test:[

      {cid:1, cond:100, weight:5}

      ,

      {cid:2, cond:200, weight:5}

      ,

      {cid:3, cond:300, weight:5}

      ,

      {cid:4, cond:400, weight:5}

      ]
      });
      db.bug.find().pretty();
      {
      "_id" : 1,
      "test" : [

      { "cid" : 1, "cond" : 100, "weight" : 5 }

      ,

      { "cid" : 2, "cond" : 200, "weight" : 5 }

      ,

      { "cid" : 3, "cond" : 300, "weight" : 5 }

      ,

      { "cid" : 4, "cond" : 400, "weight" : 5 }

      ]
      }

      db.bug.update(

      {"test.cid":3}

      , {$inc:{"test.$.weight":1}});
      db.bug.find().pretty();
      {
      "_id" : 1,
      "test" : [

      { "cid" : 1, "cond" : 100, "weight" : 5 }

      ,

      { "cid" : 2, "cond" : 200, "weight" : 5 }

      ,

      { "cid" : 3, //<< Satisfies the condition! "cond" : 300, "weight" : 6 //<< The increase is correct! }

      ,

      { "cid" : 4, "cond" : 400, "weight" : 5 }

      ]
      }

      db.bug.update({"test.cid":3, "test.cond": {$gt:150}}, {$inc:{"test.$.weight":1}});
      > db.bug.find().pretty()
      {
      "_id" : 1,
      "test" : [

      { "cid" : 1, "cond" : 100, "weight" : 5 }

      ,
      {
      "cid" : 2, //<< Not satisfy condition! ("test.cid":3)...
      "cond" : 200, //<< Satisfies the condition! ("test.cond": {$gt:150})...
      "weight" : 6 //<< Increase is this correct?...
      },
      {
      "cid" : 3, //<< Satisfies the condition! ("test.cid":3)...
      "cond" : 300, //<< Satisfies the condition! ("test.cond": {$gt:150})...
      "weight" : 6 //<< No increase
      },

      { "cid" : 4, "cond" : 400, "weight" : 5 }

      ]
      }

      db.bug.update({"test.cid":1, "test.cond": {$gt:150}}, {$inc:{"test.$.weight":1}});
      db.bug.find().pretty()
      {
      "_id" : 1,
      "test" : [
      {
      "cid" : 1, //<< Satisfies the condition! ("test.cid":1)...
      "cond" : 100, //<< Not satisfy condition! ("test.cond": {$gt:150})...
      "weight" : 5 //<< No increase
      },
      {
      "cid" : 2, //<< Not satisfy condition! ("test.cid":1)...
      "cond" : 200, //<< Satisfies the condition! ("test.cond": {$gt:150})...
      "weight" : 7 //<< Increase is this correct?...
      },

      { "cid" : 3, "cond" : 300, "weight" : 6 }

      ,

      { "cid" : 4, "cond" : 400, "weight" : 5 }

      ]
      }

            Assignee:
            Unassigned Unassigned
            Reporter:
            kijamve Kijam Lopez
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: