Skip to content

Commit 95d479c

Browse files
committed
feedback
1 parent 9911dd0 commit 95d479c

File tree

2 files changed

+47
-11
lines changed

2 files changed

+47
-11
lines changed

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

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -388,12 +388,6 @@ The preceding code examples produce the following output:
388388

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

391-
.. tip::
392-
393-
If any of the write operations fail, the {+driver-short+} raises a
394-
``BulkWriteException`` and does not perform any further operations. You can examine
395-
the properties of the exception to determine which operation failed.
396-
397391
Customize Bulk Write Operations
398392
-------------------------------
399393

@@ -490,7 +484,9 @@ object that contains the following properties:
490484
- Description
491485

492486
* - ``Acknowledged``
493-
- | Indicates whether the server acknowledged the bulk write operation.
487+
- | Indicates whether the server acknowledged the bulk write operation. If the
488+
value of this property is ``false`` and you try to access any other property
489+
of the ``ClientBulkWriteResult`` object, the driver throws an exception.
494490

495491
* - ``DeleteResults``
496492
- | An ``IReadOnlyDictionary<int, BulkWriteDeleteResult>`` object containing the
@@ -519,6 +515,45 @@ object that contains the following properties:
519515
* - ``UpsertedCount``
520516
- | The number of documents upserted, if any.
521517

518+
Handling Exceptions
519+
-------------------
520+
521+
If any of the operations in a bulk write operation fail, the {+driver-short+} throws a
522+
``ClientBulkWriteException`` and does not perform any further operations.
523+
524+
A ``ClientBulkWriteException`` object contains the following properties:
525+
526+
.. list-table::
527+
:header-rows: 1
528+
:stub-columns: 1
529+
530+
* - Property
531+
- Description
532+
* - ``connectionId``
533+
- | The connection identifier.
534+
|
535+
| **Data Type:** `ConnectionId <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.Core.Connections.ConnectionId.html>`__
536+
* - ``message``
537+
- | The error message.
538+
|
539+
| **Data Type:** {+string-data-type+}
540+
* - ``writeErrors``
541+
- | A dictionary of errors that occurred during the bulk write operation.
542+
|
543+
| **Data Type:** IReadOnlyDictionary<int, `WriteError <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.WriteError.html>`__>
544+
* - ``partialResult``
545+
- | The results of any successful operations performed before the exception was thrown.
546+
|
547+
| **Data Type:** `ClientBulkWriteResult <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.ClientBulkWriteResult.html>`__
548+
* - ``writeConcernErrors``
549+
- | Write concern errors that occurred during execution of the bulk write operation.
550+
|
551+
| **Data Type:** IReadOnlyList<`MongoWriteConcernException <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.MongoWriteConcernException.html>`__>
552+
* - ``innerException``
553+
- | The inner exception.
554+
|
555+
| **Data Type:** `Exception <https://learn.microsoft.com/dotnet/api/system.exception>`__
556+
522557
Additional Information
523558
----------------------
524559

@@ -544,3 +579,4 @@ guide, see the following API documentation:
544579
- `BulkWriteInsertOneResult <{+new-api-root+}/MongoDB.Driver/MongoClient.BulkWriteInsertOneResult.html>`__
545580
- `BulkWriteUpdateResult <{+new-api-root+}/MongoDB.Driver/MongoClient.BulkWriteUpdateResult.html>`__
546581
- `BulkWriteDeleteResult <{+new-api-root+}/MongoDB.Driver/MongoClient.BulkWriteDeleteResult.html>`__
582+
- `ClientBulkWriteException <{+new-api-root+}/MongoDB.Driver/MongoClient.ClientBulkWriteException.html>`__

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ static void BulkWriteSync()
112112
)
113113
};
114114

115-
var results = client.BulkWriteSync(bulkWriteModels);
115+
var results = client.BulkWrite(bulkWriteModels);
116116
Console.WriteLine("Bulk write results: " + results);
117117
// end-bulk-write-sync
118118
}
119-
static async void BulkWriteAsync()
119+
static async Task BulkWriteAsync()
120120
{
121121
// start-bulk-write-async
122122
var client = new MongoClient("mongodb://localhost:27017");
@@ -175,10 +175,10 @@ static void BulkWriteOptionsSync()
175175
VerboseResult = true
176176
};
177177

178-
var results = client.BulkWriteSync(deleteOneModel, clientBulkWriteOptions);
178+
var results = client.BulkWrite(deleteOneModel, clientBulkWriteOptions);
179179
// end-bulk-write-options-sync
180180
}
181-
static async void BulkWriteOptionsAsync()
181+
static async Task BulkWriteOptionsAsync()
182182
{
183183
// start-bulk-write-options-async
184184
var client = new MongoClient("mongodb://localhost:27017");

0 commit comments

Comments
 (0)