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

Regression: positional operators not used to update embedded records

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical - P2
    • Resolution: Fixed
    • Affects Version/s: 5.0.0
    • Fix Version/s: 5.0.1
    • Component/s: None
    • Labels:
      None
    • Environment:
      OSX, Ruby 2.x

      Description

      This is a critical regression from Mongoid 4.

      require 'mongoid'
       
      Mongoid.connect_to 'positional_operators_test'
       
      class Artwork
        include Mongoid::Document
        field :title, type: String
        embeds_many :images
      end
       
      class Image
        include Mongoid::Document
        embedded_in :artwork
        field :filename, type: String
        field :width, type: Integer
        field :height, type: Integer
      end
       
      artwork = Artwork.create!(title: "Mona Lisa")
      image1 = Image.new(filename: "framed.jpg")
      artwork.images << image1
      image2 = Image.new(filename: "unframed.jpg")
      artwork.images << image2
       
      #Artwork.collection.where(_id: artwork.id).update("$pull" => { "images" => { _id: image1.id } })
      Artwork.collection.find(_id: artwork.id).update_one("$pull" => { "images" => { _id: image1.id } })
       
      image2.update_attributes!(width: 30, height: 40)
       
      p artwork.reload.images.count # should be 1, in Mongoid 5 it's 2
      

      We've been through this before, see http://artsy.github.io/blog/2013/02/09/data-corruption-and-concurrent-updates-to-embedded-objects-with-mongoid/.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: