Skip to content

Commit a3b177c

Browse files
author
Karim Alibhai
committed
Add: upsertedCount to UpdateResult
1 parent 8051092 commit a3b177c

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

mongo/collection.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ func (coll *Collection) updateOrReplaceOne(ctx context.Context, filter,
499499
res := &UpdateResult{
500500
MatchedCount: r.MatchedCount,
501501
ModifiedCount: r.ModifiedCount,
502+
UpsertedCount: int64(len(r.Upserted)),
502503
}
503504
if len(r.Upserted) > 0 {
504505
res.UpsertedID = r.Upserted[0].ID

mongo/results.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ type UpdateResult struct {
7878
MatchedCount int64
7979
// The number of documents that were modified.
8080
ModifiedCount int64
81+
// The number of documents that were upserted.
82+
UpsertedCount int64
8183
// The identifier of the inserted document if an upsert took place.
8284
UpsertedID interface{}
8385
}

0 commit comments

Comments
 (0)