[CSHARP-1324] Possibility of doing an upsert with BulkWriteAsync Created: 17/Jun/15  Updated: 05/Apr/19  Resolved: 17/Jun/15

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

Type: Task Priority: Minor - P4
Reporter: Peter Gordon Assignee: Unassigned
Resolution: Done Votes: 0
Labels: question
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Is it possible to perform an upsert when doing a BulkWriteAsync operation with UpdateOneModel requests?

For instance:

List<UpdateOneModel<BsonDocument>> updateStatements = new List<UpdateOneModel<BsonDocument>>();
 
// Cannot set UpdateOptions object here to configure the udpdate to run as an upsert
updateStatements.Add(new UpdateOneModel<FactData>(filter, update));
 
var result = await db.GetCollection<BsonDocument>("test").BulkWriteAsync(updateStatements);



 Comments   
Comment by Craig Wilson [ 17/Jun/15 ]

Thanks Peter.

Comment by Peter Gordon [ 17/Jun/15 ]

You can close this issue - I was having a moment. Did not realize that UpdateOneModel had a property "IsUpsert" that enables upserts for bulk update operations.

Thanks

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