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

Positional Operator Points to Wrong Index in $set Update

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical - P2
    • Resolution: Duplicate
    • Affects Version/s: 2.6.0
    • Fix Version/s: None
    • Component/s: Querying
    • Labels:
      None
    • Operating System:
      ALL

      Description

      We have this document

      {
              "_id" : ObjectId("539fe24d822ea86809480f0c"),
              "bbs" : [
                      {
                              "_id" : ObjectId("539fe24d822ea86809480f06"),
                              "name" : "pelanggan",
                              "bbattributes" : [
                                      {
                                              "_id" : ObjectId("539fe24d822ea86809480f07"),
                                              "name" : "nama",
                                              "cell" : "l-0",
                                              "status" : "active"
                                      },
                                      {
                                              "_id" : ObjectId("539fe24d822ea86809480f08"),
                                              "name" : "dob"
                                      }
                              ]
                      },
                      {
                              "_id" : ObjectId("539fe24d822ea86809480f09"),
                              "name" : "nota",
                              "bbattributes" : [
                                      {
                                              "_id" : ObjectId("539fe24d822ea86809480f0a"),
                                              "name" : "tanggal",
                                              "cell" : "r-0",
                                              "status" : "active"
                                      },
                                      {
                                              "_id" : ObjectId("539fe24d822ea86809480f0b"),
                                              "name" : "lunas"
                                      }
                              ]
                      }
              ]
      }

      This update syntax is supposed to update bbattributes whose name is "dob", but instead it updates "nama".

      db["apps"].update({"_id": ObjectId('539fe24d822ea86809480f0c'),"bbs._id": ObjectId('539fe24d822ea86809480f06'),"bbs.0.bbattributes._id": ObjectId('539fe24d822ea86809480f08')},{"$set": {"bbs.0.bbattributes.$.status": "active", "bbs.0.bbattributes.$.cell": "l-1"}});

      Here is the result after update

      {
              "_id" : ObjectId("539fe24d822ea86809480f0c"),
              "bbs" : [
                      {
                              "_id" : ObjectId("539fe24d822ea86809480f06"),
                              "name" : "pelanggan",
                              "bbattributes" : [
                                      {
                                              "_id" : ObjectId("539fe24d822ea86809480f07"),
                                              "name" : "nama",
                                              "cell" : "l-1",
                                              "status" : "active"
                                      },
                                      {
                                              "_id" : ObjectId("539fe24d822ea86809480f08"),
                                              "name" : "dob"
                                      }
                              ]
                      },
                      {
                              "_id" : ObjectId("539fe24d822ea86809480f09"),
                              "name" : "nota",
                              "bbattributes" : [
                                      {
                                              "_id" : ObjectId("539fe24d822ea86809480f0a"),
                                              "name" : "tanggal",
                                              "cell" : "r-0"
                                      },
                                      {
                                              "_id" : ObjectId("539fe24d822ea86809480f0b"),
                                              "name" : "lunas"
                                      }
                              ]
                      }
              ]
      }

      Why does it update the wrong index, which I suspect to be always the first element?

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: