Skip to content

Commit b43b388

Browse files
p-mongop
andauthored
Fix MONGOID-5366 #upsert misuses #update_one
(#5294) * Fix MONGOID-5366 #upsert misuses #update_one * add release notes documentation Co-authored-by: Oleg Pudeyev <[email protected]>
1 parent aa05f8c commit b43b388

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

docs/release-notes/mongoid-7.4.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,3 +572,11 @@ inside a hash. For example:
572572

573573
In Mongoid 8.0, the default value of the ``Mongoid.legacy_pluck_distinct`` option will
574574
change to ``false``.
575+
576+
577+
``update_one`` Warnings in ``upsert``
578+
-------------------------------------
579+
580+
Mongoid 7.4.1 fixes incorrect usage of the driver's ``update_one`` method from
581+
Mongoid's ``upsert`` method. Mongoid's ``upsert`` actually performs a
582+
replacing upsert, and Mongoid 7.4.1 and later correctly call ``replace_one``.

docs/release-notes/mongoid-7.5.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,10 @@ The following functions are affected by this change:
8080
the selector can be strings or symbols, depending on what was passed to the
8181
operator.
8282

83+
84+
``update_one`` Warnings in ``upsert``
85+
-------------------------------------
86+
87+
Mongoid 7.5 fixes incorrect usage of the driver's ``update_one`` method from
88+
Mongoid's ``upsert`` method. Mongoid's ``upsert`` actually performs a
89+
replacing upsert, and Mongoid 7.5 correctly calls ``replace_one``.

lib/mongoid/persistable/upsertable.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module Upsertable
1818
# @return [ true ] True.
1919
def upsert(options = {})
2020
prepare_upsert(options) do
21-
collection.find(atomic_selector).update_one(
21+
collection.find(atomic_selector).replace_one(
2222
as_attributes, upsert: true, session: _session)
2323
end
2424
end

0 commit comments

Comments
 (0)