[CSHARP-3961] Determine affected documents after BulkWrite Created: 10/Nov/21 Updated: 27/Oct/23 Resolved: 11/Nov/21 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Task | Priority: | Unknown |
| Reporter: | Aleksander Sleire | Assignee: | Robert Stam |
| Resolution: | Works as Designed | Votes: | 1 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
It would be nice if there was a way to determine which documents are affected by operations during BulkWrite. I was able to find a sample response here which contain the properties `insertedIds` and `upsertedIds`. These properties are not present in the BulkWriteResult .NET class or its derived classes. If the MongoDB API supports returning deletedIds and replacedIds as well it would be nice to include those
|
| Comments |
| Comment by Robert Stam [ 11/Nov/21 ] | ||
|
One comment about BulkWriteResult: this is an abstract class with Acknowledged and Unacknowledged sub classes. Unless you chose to do an Unacknowledged write (not recommended) you can get some additional information out of the BulkWriteResult by downcasting it to the Acknowleged subclass:
You can now access the additional properties of the Acknowledged subclass (e.g. DeletedCount, InsertedCount, MatchedCount, ModifiedCount and Upserts). | ||
| Comment by Robert Stam [ 11/Nov/21 ] | ||
|
The server only returns the following information for inserts and deletes
See: https://docs.mongodb.com/manual/reference/command/insert and https://docs.mongodb.com/manual/reference/command/delete/ So it is not possible to tell which _id's were inserted or deleted. However, in the case of insert, the application provided the documents to be inserted in the first place so the application already knows the _id's. The server only returns the following information for updates:
See: https://docs.mongodb.com/manual/reference/command/delete/ So it is also not possible to tell which _id's were updated. In the specific case of an upsert it is possible to tell what _id was assigned to each upserted record. Your feature request is reasonable but cannot be implemented given the information currently being returned by the server. | ||
| Comment by Esha Bhargava [ 11/Nov/21 ] | ||
|
alesle@signicat.com Thank you for reporting the issue! We'll look into it and get back to you soon. |