-
Type: Bug
-
Resolution: Done
-
Priority: Critical - P2
-
Affects Version/s: 5.0.0
-
Component/s: None
-
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/.
- is related to
-
MONGOID-4784 Use filtered positional update operator to update nested arrays of embedded documents
- Backlog