Skip to content

Commit 75faa71

Browse files
committed
RUBY-1329 Fix bug with aggregating upserted ids for unacknowledged bulk writes
1 parent 94c44a7 commit 75faa71

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/mongo/operation/update/bulk_result.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def n_modified
9292
if n && reply.documents.first[MODIFIED]
9393
n += reply.documents.first[MODIFIED]
9494
else
95-
nil
95+
0
9696
end
9797
end
9898
end
@@ -106,7 +106,13 @@ def n_modified
106106
#
107107
# @since 2.1.0
108108
def upserted
109-
reply.documents.first[UPSERTED] || []
109+
return [] unless acknowledged?
110+
@replies.reduce([]) do |ids, reply|
111+
if upserted_ids = reply.documents.first[UPSERTED]
112+
ids += upserted_ids
113+
end
114+
ids
115+
end
110116
end
111117

112118
private

0 commit comments

Comments
 (0)