[CSHARP-3289] No return type for InsertOne and InsertMany Created: 15/Dec/20  Updated: 31/Mar/22

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

Type: New Feature Priority: Major - P3
Reporter: Nick Parker Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: next-major
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Case:

 Description   

Hi 

Please can you review the following for a future improvement:

InsertOne(), InsertOneAsync(), InsertMany(), InsertManyAsync() methods do not return anything.  They should return something I would expect an object based on the other methods below:

DeleteOne and DeleteOneAsync() returns a DeleteResult object 

UpdateOne and UpdateOneAsync() returns an UpdateResult object

 

I have worked around this using the BulkInsert/BulkInsertResult but the above insert methods should return an InsertResult object.

The Java driver does return an InsertResult object.

 

Many thanks



 Comments   
Comment by Mikalai Mazurenka (Inactive) [ 17/Dec/20 ]

nick.parker@sainsburys.co.uk thank you for reporting this issue.
Resolving it requires a breaking change. We will consider whether the change needs to be introduced for the next major release.

Comment by Nick Parker [ 17/Dec/20 ]

Hi Mikalai

An example below but I have hard coded the options and created a class for the result object:

 

public async Task<InsertResult> InsertOneAsync(TDocument model)
{
     var result = await _collection.BulkWriteAsync(
          new[] { new InsertOneModel<TDocument>(model) },
          new BulkWriteOptions { BypassDocumentValidation = false, IsOrdered = true })
          .ConfigureAwait(false);
     return InsertResult.FromCore(result); 
}

 

 

Comment by Nick Parker [ 17/Dec/20 ]

Hi Mikalai

I have created it exactly as I would have expected the driver implementation to be.

I return an InsertResult object that is populated from the BulkWriteResult objects values as follows:

InsertedCount

IsAcknowledged

It is the same as the results  returned by DeleteOne and DeleteMany methods.

Comment by Mikalai Mazurenka (Inactive) [ 15/Dec/20 ]

Hi nick.parker@sainsburys.co.uk!
Thank you for reaching out to us.
Could you please specify what information you extract from BulkWriteResult?

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