Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-3858

updates to embedded lists no longer work correctly

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 5.0.1
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      Using:

      • mongoid (~> 4.0.0)
      • moped (~> 2.0.1)

      Mongo DB:

      • 2.6.3 & 2.6.5

      NOTE: it worked before upgrading MongoDB. Worked on 2.4.9

      Steps to reproduce:

      • In a Rails project console, you can run the following script.
      class Duplicatable
        include Mongoid::Document
        include Mongoid::Timestamps
      
        embeds_many :embedded_lists
      
      end
      
      class EmbeddedList
        include Mongoid::Document
      
        embedded_in :duplicatable
        embeds_many :embedded_list_items
      
      end
      
      class EmbeddedListItem
        include Mongoid::Document
      
        embedded_in :embedded_list
        embeds_many :embedded_list_items
      
        field :name, type: String
        field :sort_index, type: Integer
      end
      
      d = Duplicatable.create
      list = d.embedded_lists.create
      list.embedded_list_items.create name: 'first', sort_index: 0
      last = list.embedded_list_items.create name: 'second', sort_index: 1
      
      list.reload
      list_item = list.embedded_list_items.find last.id.to_s 
      
      list_item.name = "last"
      list_item.save
      
      list_item
      

      The above code sets up the relationships and the data. It then changes the last entry's name from "second" to "last", saves it and displays what the item looks like. It should be something like this...

      #=> #<EmbeddedListItem _id: 546289546d61722877040000, name: "last", sort_index: 1>
      

      Now reload the item and you will find that it did not change.

      list_item.reload
      #=> #<EmbeddedListItem _id: 546289546d61722877040000, name: "second", sort_index: 1>
      

      And instead, it changed the first item in the list (one with a different ID as well).

      list.reload
      list.embedded_list_items
      #=> [#<EmbeddedListItem _id: 546289426d61722877030000, name: "last", sort_index: 0>, #<EmbeddedListItem _id: 546289546d61722877040000, name: "second", sort_index: 1>]
      

      This was verified on an Ubuntu Linux machine against MongoDB 2.6.3 and reproduced on a Mac OSX against MongoDB 2.6.5.

      It worked correctly (making the change to the correct item in the embedded list) on the Mac OSX when against MongoDB 2.4.9.

            Assignee:
            dianna.hohensee@mongodb.com Dianna Hohensee (Inactive)
            Reporter:
            brainlid brainlid
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: