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

Positional Operator Points to Wrong Index in $set Update

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Critical - P2 Critical - P2
    • None
    • Affects Version/s: 2.6.0
    • Component/s: Querying
    • None
    • ALL

      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?

            Assignee:
            scotthernandez Scott Hernandez (Inactive)
            Reporter:
            wongsolo yudho ahmad diponegoro
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: