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

Regression: positional operators not used to update embedded records

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

      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/.

            Assignee:
            durran.jordan@mongodb.com Durran Jordan
            Reporter:
            dblock Daniel Doubrovkine
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: