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

Subcollection update does not work.

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.6.5
    • Component/s: Querying
    • None
    • ALL
    • Hide
      $ mongo ran_q_test
      
      > db.users.update({"_id":ObjectId("54a251b862656e1dc1000000"),"contacts._id":ObjectId("54a251b862656e1dc1010000"),"contacts.0.contact_ranks._id": ObjectId("54a251b862656e1dc1030000")}, {"$set": {"contacts.0.contact_ranks.$.value": 200000}})
      

      You will expect that contact_rank document with the id: 54a251b862656e1dc1030000 will have updated attribute "value", n'est ce pas?
      But somehow you discover that the other document was updated with the id 54a251b862656e1dc1020000
      My conclusion is that it updates the first element in sub collection.

      > db.users.find()[0].contacts[0].contact_ranks
      [
      	{
      		"_id" : ObjectId("54a251b862656e1dc1020000"),
      		"_type" : "ContactRank",
      		"name" : "sexy",
      		"value" : 200000
      	},
      	{
      		"_id" : ObjectId("54a251b862656e1dc1030000"),
      		"_type" : "ContactRank",
      		"name" : "cool"
      	},
      	{
      		"_id" : ObjectId("54a251b862656e1dc1040000"),
      		"_type" : "ContactRank",
      		"name" : "hot"
      	},
      	{
      		"_id" : ObjectId("54a251b862656e1dc1050000"),
      		"_type" : "ContactRank",
      		"name" : "smart"
      	},
      	{
      		"_id" : ObjectId("54a251b862656e1dc1060000"),
      		"_type" : "ContactRank",
      		"name" : "ugly"
      	},
      	{
      		"_id" : ObjectId("54a251b862656e1dc1070000"),
      		"_type" : "ContactRank",
      		"name" : "angry"
      	}
      ]
      
      Show
      $ mongo ran_q_test > db.users.update({ "_id" :ObjectId( "54a251b862656e1dc1000000" ), "contacts._id" :ObjectId( "54a251b862656e1dc1010000" ), "contacts.0.contact_ranks._id" : ObjectId( "54a251b862656e1dc1030000" )}, { "$set" : { "contacts.0.contact_ranks.$.value" : 200000}}) You will expect that contact_rank document with the id: 54a251b862656e1dc1030000 will have updated attribute "value", n'est ce pas? But somehow you discover that the other document was updated with the id 54a251b862656e1dc1020000 My conclusion is that it updates the first element in sub collection. > db.users.find()[0].contacts[0].contact_ranks [ { "_id" : ObjectId( "54a251b862656e1dc1020000" ), "_type" : "ContactRank" , "name" : "sexy" , "value" : 200000 }, { "_id" : ObjectId( "54a251b862656e1dc1030000" ), "_type" : "ContactRank" , "name" : "cool" }, { "_id" : ObjectId( "54a251b862656e1dc1040000" ), "_type" : "ContactRank" , "name" : "hot" }, { "_id" : ObjectId( "54a251b862656e1dc1050000" ), "_type" : "ContactRank" , "name" : "smart" }, { "_id" : ObjectId( "54a251b862656e1dc1060000" ), "_type" : "ContactRank" , "name" : "ugly" }, { "_id" : ObjectId( "54a251b862656e1dc1070000" ), "_type" : "ContactRank" , "name" : "angry" } ]

      Subcollection in third level updates only the first element and not the correct one. Please open the dump and run the attached queries. I've reported this bug for version 2.6.3 but I still have it in amazon mongodb official product
      https://aws.amazon.com/marketplace/pp/B00COAAEH8/ref=sp_mpg_product_title?ie=UTF8&sr=0-2
      that uses 2.6.5

      And I want a ticket to MongoDB world !!!!

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

              Created:
              Updated:
              Resolved: