Skip to content

Commit 3013cab

Browse files
committed
merge
1 parent 7a1729b commit 3013cab

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

source/fundamentals/crud/write-operations/bulk-write.txt

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@ Bulk Write Operations
2020
Overview
2121
--------
2222

23+
This guide shows you how to use the {+driver-short+} to perform **bulk write operations**
24+
that include multiple write operations in a single database call.
25+
2326
Consider a scenario in which you want to insert a document into a collection,
2427
update multiple other documents, then delete a document. If you use
25-
individual methods, each operation requires its own database call. This guide
26-
shows you how to use bulk write operations to perform multiple write operations
27-
in a single database call.
28+
individual methods, each operation requires its own database call. If you use
29+
a bulk write operation, you can improve efficiency by performing multiple write
30+
operations in a single database call.
2831

2932
Sample Data
3033
~~~~~~~~~~~
@@ -51,11 +54,10 @@ The following sections show how to create and use instances of the preceding cla
5154

5255
.. tip:: Bulk Write Operations with POCOs
5356

54-
The examples in this guide use ``BsonDocument`` as the type for ``TDocument``.
55-
You can also use a Plain Old CLR Object (POCO) as the type for ``TDocument``.
56-
57-
To use a POCO, define a class that represents the documents in your collection.
58-
The class must have properties that match the fields in your documents.
57+
The examples in this guide use the ``BsonDocument`` type for the ``TDocument`` type
58+
in all generic classes. You can also use a Plain Old CLR Object (POCO) for these
59+
classes. To do so, you must define a class that represents the documents in your
60+
collection. The class must have properties that match the fields in your documents.
5961
For more information, see :ref:`<csharp-poco>`.
6062

6163
Insert Operations
@@ -164,11 +166,11 @@ parameters:
164166
| **Data Type:** `IEnumerable<ArrayFilterDefinition> <https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1?view=net-8.0>`__
165167
| **Default:** ``null``
166168

167-
The following example creates an instance of the ``BulkWriteUpdateOneModel<TDocument>``
168-
class, and uses ``BsonDocument`` as the type for ``TDocument``. The
169-
filter matches the first document in the ``sample_restaurants.restaurants`` collection
170-
where the value of the ``name`` field is ``"Mongo's Deli"``. The update operation sets
171-
the value of the ``cuisine`` field to ``"Sandwiches and Salads"``.
169+
In the following code example, the ``BulkWriteUpdateOneModel<BsonDocument>`` object
170+
represents an update operation on the ``sample_restaurants.restaurants`` collection.
171+
The operation matches the first document in the collection where the value of the ``name``
172+
field is ``"Mongo's Deli"``. It then updates the value of the ``cuisine`` field in the
173+
matched document to ``"Sandwiches and Salads"``.
172174

173175
.. literalinclude:: /includes/fundamentals/code-examples/BulkWrite.cs
174176
:start-after: start-bulk-update-one
@@ -347,9 +349,10 @@ Run the Write Operations
347349
------------------------
348350

349351
After you define a ``BulkWriteModel`` instance for each operation that you want to perform,
350-
pass an ``IReadOnlyList`` collection of these instances to the ``BulkWrite()`` or
351-
``BulkWriteAsync()`` method. By default, these methods run the operations in the order
352-
they're defined in the collection.
352+
create an instance of a class that implements the ``IReadOnlyList`` interface. Add your
353+
``BulkWriteModel`` objects to this ``IReadOnlyList``, then pass the ``IReadOnlyList``
354+
to the ``BulkWrite()`` or ``BulkWriteAsync()`` method. By default, these methods run
355+
the operations in the order they're defined in the collection.
353356

354357
.. tip:: IReadOnlyList
355358

@@ -388,7 +391,7 @@ The preceding code examples produce the following output:
388391

389392
BulkWriteResult({'writeErrors': [], 'writeConcernErrors': [], 'nInserted': 2, 'nUpserted': 0, 'nMatched': 2, 'nModified': 2, 'nRemoved': 1, 'upserted': []}, acknowledged=True)
390393

391-
.. tip:: Troubleshooting Bulk Write Operations
394+
.. tip::
392395

393396
If any of the write operations fail, the {+driver-short+} raises a
394397
``BulkWriteException`` and does not perform any further operations. You can examine

source/includes/fundamentals/code-examples/BulkWrite.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static void BulkWriteSync()
8181
var client = new MongoClient("mongodb://localhost:27017");
8282
var collection = "sample_restaurants.restaurants";
8383

84-
var bulkWriteModels = new WriteModel<BsonDocument>[]
84+
var bulkWriteModels = new[]
8585
{
8686
new BulkWriteInsertOneModel<BsonDocument>(
8787
collection,
@@ -122,7 +122,7 @@ static async void BulkWriteAsync()
122122
var client = new MongoClient("mongodb://localhost:27017");
123123
var collection = "sample_restaurants.restaurants";
124124

125-
var bulkWriteModels = new WriteModel<BsonDocument>[]
125+
var bulkWriteModels = new[]
126126
{
127127
new BulkWriteInsertOneModel<BsonDocument>(
128128
collection,

0 commit comments

Comments
 (0)