While updating a subcollection only first member is updated

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Major - P3
    • 12_01_17
    • Affects Version/s: None
    • Component/s: BSON
    • None
    • Environment:
      ubuntu
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Version 2.6.3 of mongod:
      While updating a subdocument rank that is part of contact that is part of user:

      This is a MOPED log:
      MOPED: 127.0.0.1:27017 UPDATE database=ran_q_test collection=users selector=

      {"_id"=>BSON::ObjectId('54a17a0a62656e4271000000'), "contacts._id"=>BSON::ObjectId('54a17a0a62656e4271010000'), "contacts.0.contact_ranks._id"=>BSON::ObjectId('54a17a0a62656e4271020000')}

      update={"$set"=>{"contacts.0.contact_ranks.$.value"=>100}} flags=[]
      COMMAND database=ran_q_test command={:getlasterror=>1, :w=>1} runtime: 2.5676ms
      MOPED: 127.0.0.1:27017 UPDATE database=ran_q_test collection=users selector=

      {"_id"=>BSON::ObjectId('54a17a0a62656e4271000000'), "contacts._id"=>BSON::ObjectId('54a17a0a62656e4271010000'), "contacts.0.contact_ranks._id"=>BSON::ObjectId('54a17a0a62656e4271030000')}

      update={"$set"=>{"contacts.0.contact_ranks.$.value"=>200}} flags=[]
      COMMAND database=ran_q_test command={:getlasterror=>1, :w=>1} runtime: 2.3991ms
      MOPED: 127.0.0.1:27017 UPDATE database=ran_q_test collection=users selector=

      {"_id"=>BSON::ObjectId('54a17a0a62656e4271000000'), "contacts._id"=>BSON::ObjectId('54a17a0a62656e4271010000'), "contacts.0.contact_ranks._id"=>BSON::ObjectId('54a17a0a62656e4271040000')}

      update={"$set"=>{"contacts.0.contact_ranks.$.value"=>300}} flags=[]
      COMMAND database=ran_q_test command={:getlasterror=>1, :w=>1} runtime: 2.3387ms
      MOPED: 127.0.0.1:27017 UPDATE database=ran_q_test collection=users selector=

      {"_id"=>BSON::ObjectId('54a17a0a62656e4271000000'), "contacts._id"=>BSON::ObjectId('54a17a0a62656e4271010000'), "contacts.0.contact_ranks._id"=>BSON::ObjectId('54a17a0a62656e4271050000')}

      update={"$set"=>{"contacts.0.contact_ranks.$.value"=>400}} flags=[]
      COMMAND database=ran_q_test command={:getlasterror=>1, :w=>1} runtime: 2.1929ms
      MOPED: 127.0.0.1:27017 UPDATE database=ran_q_test collection=users selector=

      {"_id"=>BSON::ObjectId('54a17a0a62656e4271000000'), "contacts._id"=>BSON::ObjectId('54a17a0a62656e4271010000'), "contacts.0.contact_ranks._id"=>BSON::ObjectId('54a17a0a62656e4271060000')}

      update={"$set"=>{"contacts.0.contact_ranks.$.value"=>500}} flags=[]
      COMMAND database=ran_q_test command={:getlasterror=>1, :w=>1} runtime: 2.2453ms
      MOPED: 127.0.0.1:27017 UPDATE database=ran_q_test collection=users selector=

      {"_id"=>BSON::ObjectId('54a17a0a62656e4271000000'), "contacts._id"=>BSON::ObjectId('54a17a0a62656e4271010000'), "contacts.0.contact_ranks._id"=>BSON::ObjectId('54a17a0a62656e4271070000')}

      update={"$set"=>{"contacts.0.contact_ranks.$.value"=>600}} flags=[]
      COMMAND database=ran_q_test command={:getlasterror=>1, :w=>1} runtime: 2.2785ms

      But seems that instead of updating each document it updates always the first one. The result:
      > ranks = db.users.find()[0].contacts[0].contact_ranks
      [

      { "_id" : ObjectId("54a179a162656e40ac020000"), "_type" : "ContactRank", "name" : "sexy", "value" : 600 }

      ,

      { "_id" : ObjectId("54a179a162656e40ac030000"), "_type" : "ContactRank", "name" : "cool" }

      ,

      { "_id" : ObjectId("54a179a162656e40ac040000"), "_type" : "ContactRank", "name" : "hot" }

      ,

      { "_id" : ObjectId("54a179a162656e40ac050000"), "_type" : "ContactRank", "name" : "smart" }

      ,

      { "_id" : ObjectId("54a179a162656e40ac060000"), "_type" : "ContactRank", "name" : "ugly" }

      ,

      { "_id" : ObjectId("54a179a162656e40ac070000"), "_type" : "ContactRank", "name" : "angry" }

      ]

      In 2.4.12 it works just fine, and the result as it should be:
      > ranks = db.users.find()[0].contacts[0].contact_ranks
      [

      { "_id" : ObjectId("54a17b2262656e461c020000"), "_type" : "ContactRank", "name" : "sexy", "value" : 100 }

      ,

      { "_id" : ObjectId("54a17b2262656e461c030000"), "_type" : "ContactRank", "name" : "cool", "value" : 200 }

      ,

      { "_id" : ObjectId("54a17b2262656e461c040000"), "_type" : "ContactRank", "name" : "hot", "value" : 300 }

      ,

      { "_id" : ObjectId("54a17b2262656e461c050000"), "_type" : "ContactRank", "name" : "smart", "value" : 400 }

      ,

      { "_id" : ObjectId("54a17b2362656e461c060000"), "_type" : "ContactRank", "name" : "ugly", "value" : 500 }

      ,

      { "_id" : ObjectId("54a17b2362656e461c070000"), "_type" : "ContactRank", "name" : "angry", "value" : 600 }

      ]

      I think it is a very serious bug, please reply urgently.
      Kind regards, Benjamin Harel.

        1. blob.jpg
          blob.jpg
          80 kB
        2. dump.tgz
          0.9 kB
        3. dump.tgz
          0.9 kB

              Assignee:
              Unassigned
              Reporter:
              Benjamin Harel
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: