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

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Critical - P2 Critical - P2
    • None
    • 2.2.0
    • JavaScript, Write Ops
    • Linux
    • 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

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

            Dates

              Created:
              Updated:
              Resolved: