Skip to content

Commit bf7b610

Browse files
committed
Upsert checks if an existing document was updated
1 parent 243d1ec commit bf7b610

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

lib/mongo/operation/write/bulk/bulk_update/result.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,11 @@ def n_matched
149149
private
150150

151151
def upsert?(reply)
152-
!reply.documents.first[UPDATED_EXISTING]
152+
!updated_existing?(reply) && reply.documents.first[N] == 1
153+
end
154+
155+
def updated_existing?(reply)
156+
reply.documents.first[UPDATED_EXISTING]
153157
end
154158
end
155159
end

lib/mongo/operation/write/update/result.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def upserted_id
147147
private
148148

149149
def upsert?
150-
!updated_existing?
150+
!updated_existing? && n == 1
151151
end
152152

153153
def updated_existing?

0 commit comments

Comments
 (0)