[CSHARP-3724] BulkWriteResult doesn't have UpsertedCount Created: 02/Jul/21  Updated: 27/Oct/23  Resolved: 12/Jul/21

Status: Closed
Project: C# Driver
Component/s: API
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Max Drachsh Assignee: Mikalai Mazurenka (Inactive)
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

The BulkWriteResult contains properties like ModifiedCount, InsertedCount, and so on. But it doesn't have UpsertedCount.

F.e I have list of updating models:

 

 // some method that creates models for updating
 private static UpdateOneModel<Entity> CreateUpdateModel(Record item)
 {
   var filter = Builders<Entity>.Filter.Eq(a => a.Id, item.Id);
   var update = Builders<Entity>.Update
     .Set(x => x.UserName, item.UserName)
      ...
 
   return new UpdateOneModel<Entity>(filter, update)
     {IsUpsert = true};
 }

 

And then call:

var bulkResult = await _collection.BulkWriteAsync(bulkOps);

 From the bulkResult I cannot understand how much was upserted, moreover, InsertedCount is 0 also.

 



 Comments   
Comment by Mikalai Mazurenka (Inactive) [ 12/Jul/21 ]

Hi sharok89@gmail.com,

You can get the UpsertedCount by accessing the Upserts property, e.g.

var bulkResult = await _collection.BulkWriteAsync(bulkOps);
var upsertedCount = bulkResult.Upserts.Count;

Adding UpsertedCount property into BulkWriteResult would be redundant.

Comment by Esha Bhargava [ 02/Jul/21 ]

sharok89@gmail.com Thank you for reporting the issue! We'll look into it and get back to you soon.

Generated at Wed Feb 07 21:46:07 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.