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

update of element of a sublist updates the wrong element depending on the order the request was built

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Critical - P2 Critical - P2
    • None
    • Affects Version/s: 2.2.0
    • Component/s: JavaScript, Write Ops
    • Environment:
      Linux
    • Linux

      Here are the data before update

      {
              "_id" : ObjectId("506c614a80178fe821c091bf"),
              "identifier" : "1",
              "list" : [
                      {
                              "identifier" : {
                                      "id" : "1",
                                      "type" : "raw"
                              },
                              "name" : "name1"
                      },
                      {
                              "identifier" : {
                                      "id" : "2",
                                      "type" : "raw"
                              },
                              "name" : "name2"
                      }
              ]
      }
      

      I try to update the second element

      db.test.update({identifier:"1","list.identifier.id":"2","list.identifier.type":"raw"},{$set:{"list.$.name":"name22"}},false,true);
      

      ...but mongo updated the first

      {
              "_id" : ObjectId("506c614a80178fe821c091bf"),
              "identifier" : "1",
              "list" : [
                      {
                              "identifier" : {
                                      "id" : "1",
                                      "type" : "raw"
                              },
                              "name" : "name22"
                      },
                      {
                              "identifier" : {
                                      "id" : "2",
                                      "type" : "raw"
                              },
                              "name" : "name2"
                      }
              ]
      }
      

      This time I give a different order for the request

      db.test.update({identifier:"1","list.identifier.type":"raw","list.identifier.id":"2"},{$set:{"list.$.name":"name222"}},false,true);
      

      ...and mongo updated the correct element

      {
              "_id" : ObjectId("506c614a80178fe821c091bf"),
              "identifier" : "1",
              "list" : [
                      {
                              "identifier" : {
                                      "id" : "1",
                                      "type" : "raw"
                              },
                              "name" : "name22"
                      },
                      {
                              "identifier" : {
                                      "id" : "2",
                                      "type" : "raw"
                              },
                              "name" : "name222"
                      }
              ]
      }
      

        1. test.js
          1 kB
          Benoît Fonty

            Assignee:
            Unassigned Unassigned
            Reporter:
            bfonty Benoît Fonty
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: