Skip to content

Commit 445bfc7

Browse files
author
rstam
committed
CSHARP-797: Make BulkWrite method internal
In 1.9.0-rc0 you had the choice of either using the BulkWrite method of MongoCollection to execute a bulk write operation, or you could choose the more verbose fluent bulk API if you wished. In 1.9.0-rc1 we are making the BulkWrite method internal and requiring that you use the fluent bulk API instead. To illustrate the difference between the two approaches, imagine you have an array of ids of documents you want to delete: var ids = new BsonValue[] { 1, 2, 3 }; Using the BulkWrite method you could use LINQ to transform the list of ids into a list of delete requests and pass them to the BulkWrite method: collection.BulkWrite(new BulkWriteArgs { Requests = ids.Select(id => (WriteRequest)new DeleteRequest(Query.EQ("_id", id))) }); Using the fluent bulk API you need to create an intermediate builder object and use it in a foreach loop to build up the multiple delete requests, and then call Execute on the intermediate builder object: var bulk = collection.InitializeOrderedBulkOperation(); foreach (var id in ids) { bulk.Find(Query.EQ("_id", id)).RemoveOne(); } bulk.Execute(); This change was made to make the .NET driver consistent with other drivers, where the fluent bulk API is the only way to create and execute batch writes.
1 parent b0eec76 commit 445bfc7

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

MongoDB.Driver/MongoCollection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public virtual CommandResult AggregateExplain(AggregateArgs args)
188188
/// <returns>
189189
/// A BulkWriteResult.
190190
/// </returns>
191-
public virtual BulkWriteResult BulkWrite(BulkWriteArgs args)
191+
internal virtual BulkWriteResult BulkWrite(BulkWriteArgs args)
192192
{
193193
if (args == null)
194194
{

MongoDB.Driver/Operations/BulkWriteArgs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace MongoDB.Driver
2121
/// <summary>
2222
/// Represents the arguments to a BulkWrite method (BulkDelete, BulkInsert, BulkUpdate or BulkWrite).
2323
/// </summary>
24-
public class BulkWriteArgs
24+
internal class BulkWriteArgs
2525
{
2626
// private fields
2727
private Action<InsertRequest> _assignId;

0 commit comments

Comments
 (0)