@@ -309,19 +309,16 @@ class BulkWriteOptions {
309
309
``` typescript
310
310
class BulkWriteResult {
311
311
/**
312
- * Indicates whether this write result was acknowledged. If not, then all other members of this
313
- * result will be undefined.
312
+ * Indicates whether this write result was acknowledged.
314
313
*
315
- * NOT REQUIRED TO IMPLEMENT. See below for more guidance on modeling unacknowledged results.
314
+ * NOT REQUIRED TO IMPLEMENT. See below for guidance on modeling unacknowledged results.
316
315
*/
317
316
acknowledged: Boolean ;
318
317
319
318
/**
320
- * Indicates whether the results are verbose. If false, the insertResults, updateResults, and
321
- * deleteResults fields in this result will be undefined.
319
+ * Indicates whether this result contains verbose results.
322
320
*
323
- * NOT REQUIRED TO IMPLEMENT. See below for other ways to differentiate summary results from
324
- * verbose results.
321
+ * NOT REQUIRED TO IMPLEMENT. See below for guidance on modeling verbose results.
325
322
*/
326
323
hasVerboseResults: Boolean ;
327
324
@@ -352,16 +349,22 @@ class BulkWriteResult {
352
349
353
350
/**
354
351
* The results of each individual insert operation that was successfully performed.
352
+ *
353
+ * NOT REQUIRED TO IMPLEMENT. See below for guidance on modeling verbose results.
355
354
*/
356
355
insertResults: Map <Index , InsertOneResult >;
357
356
358
357
/**
359
358
* The results of each individual update operation that was successfully performed.
359
+ *
360
+ * NOT REQUIRED TO IMPLEMENT. See below for guidance on modeling verbose results.
360
361
*/
361
362
updateResults: Map <Index , UpdateResult >;
362
363
363
364
/**
364
365
* The results of each individual delete operation that was successfully performed.
366
+ *
367
+ * NOT REQUIRED TO IMPLEMENT. See below for guidance on modeling verbose results.
365
368
*/
366
369
deleteResults: Map <Index , DeleteResult >;
367
370
}
@@ -404,23 +407,58 @@ class DeleteResult {
404
407
405
408
#### Unacknowledged results
406
409
407
- ` BulkWriteResult ` has an optional ` acknowledged ` field to indicate whether the result was acknowledged. This is not
408
- required to implement . Drivers should follow the guidance in the CRUD specification
410
+ Users MUST be able to discern whether a ` BulkWriteResult ` contains acknowledged results without inspecting the
411
+ configured write concern . Drivers should follow the guidance in the CRUD specification
409
412
[ here] ( ../crud/crud.md#write-results ) to determine how to model unacknowledged results.
410
413
414
+ If drivers expose the ` acknowledged ` field, they MUST document what will happen if a user attempts to access a result
415
+ value when ` acknowledged ` is ` false ` (e.g. an undefined value is returned or an error is thrown).
416
+
411
417
#### Summary vs. verbose results
412
418
413
- Users MUST be able to discern whether a ` BulkWriteResult ` contains summary or verbose results without inspecting the
414
- value provided for ` verboseResults ` in ` BulkWriteOptions ` . Drivers MUST implement this in one of the following ways:
419
+ When a user does not set the ` verboseResults ` option to ` true ` , drivers MUST NOT populate the ` insertResults ` ,
420
+ ` updateResults ` , and ` deleteResults ` fields. Users MUST be able to discern whether a ` BulkWriteResult ` contains these
421
+ verbose results without inspecting the value provided for ` verboseResults ` in ` BulkWriteOptions ` . Drivers can implement
422
+ this in a number of ways, including:
423
+
424
+ - Expose the ` hasVerboseResults ` field in ` BulkWriteResult ` as defined above. Document what will happen if a user
425
+ attempts to access the ` insertResults ` , ` updateResults ` , or ` deleteResults ` values when ` hasVerboseResults ` is false.
426
+ Drivers MAY raise an error if a user attempts to access one of these values when ` hasVerboseResults ` is false.
427
+ - Embed the verbose results in an optional type:
428
+
429
+ ``` typescript
430
+ class BulkWriteResult {
431
+ /**
432
+ * The results of each individual write operation that was successfully performed.
433
+ *
434
+ * This value will only be populated if the verboseResults option was set to true.
435
+ */
436
+ verboseResults: Optional <VerboseResults >;
437
+
438
+ /* rest of fields */
439
+ }
440
+
441
+ class VerboseResults {
442
+ /**
443
+ * The results of each individual insert operation that was successfully performed.
444
+ */
445
+ insertResults: Map <Index , InsertOneResult >;
446
+
447
+ /**
448
+ * The results of each individual update operation that was successfully performed.
449
+ */
450
+ updateResults: Map <Index , UpdateResult >;
415
451
416
- - Expose the ` hasVerboseResults ` field in ` BulkWriteResult ` as defined above. Document that ` insertResults ` ,
417
- ` updateResults ` , and ` deleteResults ` will be undefined when ` hasVerboseResults ` is false. Raise an error if a user
418
- tries to access one of these fields when ` hasVerboseResults ` is false.
419
- - Implement the ` insertResults ` , ` updateResults ` , and ` deleteResults ` fields as optional types and document that they
420
- will be unset when ` verboseResults ` is false.
421
- - Introduce separate ` SummaryBulkWriteResult ` and ` VerboseBulkWriteResult ` types. ` VerboseBulkWriteResult ` MUST have all
422
- of the required fields defined on ` BulkWriteResult ` above. ` SummaryBulkWriteResult ` MUST have all of the required
423
- fields defined on ` BulkWriteResult ` above except ` insertResults ` , ` updateResults ` , and ` deleteResults ` .
452
+ /**
453
+ * The results of each individual delete operation that was successfully performed.
454
+ */
455
+ deleteResults: Map <Index , DeleteResult >;
456
+ }
457
+ ```
458
+
459
+ - Define separate ` SummaryBulkWriteResult ` and ` VerboseBulkWriteResult ` types. ` SummaryBulkWriteResult ` MUST only
460
+ contain the summary result fields, and ` VerboseBulkWriteResult ` MUST contain both the summary and verbose result
461
+ fields. Return ` VerboseBulkWriteResult ` when ` verboseResults ` was set to true and ` SummaryBulkWriteResult ` otherwise.
424
462
425
463
#### Individual results
426
464
@@ -871,6 +909,8 @@ batch-splitting to standardize implementations across drivers and simplify batch
871
909
872
910
## ** Changelog**
873
911
912
+ - 2024-09-30: Define more options for modeling summary vs. verbose results.
913
+
874
914
- 2024-09-25: Add ` collation ` field to ` update ` document and clarify usage of ` updateMods ` .
875
915
876
916
- 2024-09-25: Update the ` partialResult ` population logic to account for ordered bulk writes.
0 commit comments