Skip to content

Commit 43b45d6

Browse files
committed
find and modifies return nil if value is an empty doc
1 parent bf7b610 commit 43b45d6

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/mongo/collection/view/writable.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,10 @@ def find_one_and_update(document, opts = {})
7777
cmd[:update] = document
7878
cmd[:fields] = projection if projection
7979
cmd[:sort] = sort if sort
80-
cmd[:new] = (opts[:return_document] == :after ? true : false) if opts[:return_document]
80+
cmd[:new] = !!(opts[:return_document] && opts[:return_document] == :after)
8181
cmd[:upsert] = opts[:upsert] if opts[:upsert]
82-
database.command(cmd).first['value']
82+
value = database.command(cmd).first['value']
83+
value unless value.nil? || value.empty?
8384
end
8485

8586
# Remove documents from the collection.

0 commit comments

Comments
 (0)