[CSHARP-1581] Update documentation for BulkWrite to show how Upserts are done Created: 28/Feb/16  Updated: 31/Mar/22

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

Type: Improvement Priority: Minor - P4
Reporter: Zeioth Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: bulk, neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Major Change

 Description   

I migrated from 1.9 to 2.2 and reading the documentation I was surprised to discover that is not possible to upsert during a bulk operation anymore, since operations don't allow options.

bulkOps.Add(new UpdateOneModel<BsonDocument>(filter, update));
collection.BulkWrite(bulkOps);

Should be

options.isUpsert = true;
bulkOps.Add(new UpdateOneModel<BsonDocument>(filter, update, options));
collection.BulkWrite(bulkOps);

Is this work in progress, intended, or I'm missing something? Thank you.



 Comments   
Comment by Zeioth [ 28/Feb/16 ]

Ok it's possible, like:

bulkOps.Add(new UpdateOneModel<BsonDocument>(filter, update) { IsUpsert = true });

instead of:

bulkOps.Add(new UpdateOneModel<BsonDocument>(filter, update, options));

May it would be a good idea to add this to the documentation, since it's not very intuitive.

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