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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical - P2
    • Resolution: Works as Designed
    • Affects Version/s: 2.2.0
    • Fix Version/s: None
    • Component/s: JavaScript, Write Ops
    • Labels:
    • Environment:
      Linux
    • Operating System:
      Linux

      Description

      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"
                      }
              ]
      }

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved: