Skip to content

Commit 4cdc2bd

Browse files
p-mongop
andauthored
MONGOID-5340 Add $set behavior change in Mongoid 7.1 to release notes (#5321)
Co-authored-by: Oleg Pudeyev <[email protected]>
1 parent 5fa841a commit 4cdc2bd

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

docs/release-notes/mongoid-7.0.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,31 @@ supports Rails 5.1-6.0.
3838
New in version 7.0.3: Embedded matchers now support the ``$eq`` operator.
3939

4040
New in version 7.0.5: Mongoid now officially supports Rails 6.0.
41+
42+
43+
``set`` Overwrites Complete Document
44+
------------------------------------
45+
46+
**Breaking change:** In Mongoid 7.0.2 and higher, ``set`` writes
47+
the provided attributes as the complete document (or sub-document), replacing
48+
any other attributes stored in the database. This behavior matches that of
49+
MongoDB ``$set`` operator. In Mongoid 7.0.1 and lower, ``set`` retained other
50+
attributes present in the database below the document being written:
51+
52+
.. code-block:: ruby
53+
54+
class Product
55+
include Mongoid::Document
56+
57+
field :tags, type: Hash
58+
end
59+
60+
product = Product.new(tags: {color: 'black'})
61+
product.set(tags: {size: 'large'})
62+
63+
product
64+
# Mongoid 7.0.2+:
65+
# => #<Product _id: 62ab9770ce4ef31ac572679c, tags: {:size=>"large"}>
66+
#
67+
# Mongoid 7.0.1:
68+
# => #<Product _id: 62ab9770ce4ef31ac572679c, tags: {:color=>"black", :size=>"large"}>

docs/release-notes/mongoid-7.1.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,34 @@ example, the following two approaches result in the same generated selector:
254254
# embedded: false>
255255

256256

257+
``set`` Overwrites Complete Document
258+
------------------------------------
259+
260+
**Breaking change:** In Mongoid 7.1 (and 7.0.2 and higher), ``set`` writes
261+
the provided attributes as the complete document (or sub-document), replacing
262+
any other attributes stored in the database. This behavior matches that of
263+
MongoDB ``$set`` operator. In Mongoid 7.0.1 and lower, ``set`` retained other
264+
attributes present in the database below the document being written:
265+
266+
.. code-block:: ruby
267+
268+
class Product
269+
include Mongoid::Document
270+
271+
field :tags, type: Hash
272+
end
273+
274+
product = Product.new(tags: {color: 'black'})
275+
product.set(tags: {size: 'large'})
276+
277+
product
278+
# Mongoid 7.0.2+, 7.1+:
279+
# => #<Product _id: 62ab9770ce4ef31ac572679c, tags: {:size=>"large"}>
280+
#
281+
# Mongoid 7.0.1:
282+
# => #<Product _id: 62ab9770ce4ef31ac572679c, tags: {:color=>"black", :size=>"large"}>
283+
284+
257285
Ruby Version Support
258286
--------------------
259287

0 commit comments

Comments
 (0)