Skip to content

Commit 1de6a19

Browse files
DRIVERS-2967 Define more options for modeling bulk write results (#1667)
1 parent c5dcae5 commit 1de6a19

File tree

1 file changed

+59
-19
lines changed

1 file changed

+59
-19
lines changed

source/crud/bulk-write.md

Lines changed: 59 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -309,19 +309,16 @@ class BulkWriteOptions {
309309
```typescript
310310
class BulkWriteResult {
311311
/**
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.
314313
*
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.
316315
*/
317316
acknowledged: Boolean;
318317

319318
/**
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.
322320
*
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.
325322
*/
326323
hasVerboseResults: Boolean;
327324

@@ -352,16 +349,22 @@ class BulkWriteResult {
352349

353350
/**
354351
* 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.
355354
*/
356355
insertResults: Map<Index, InsertOneResult>;
357356

358357
/**
359358
* 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.
360361
*/
361362
updateResults: Map<Index, UpdateResult>;
362363

363364
/**
364365
* 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.
365368
*/
366369
deleteResults: Map<Index, DeleteResult>;
367370
}
@@ -404,23 +407,58 @@ class DeleteResult {
404407

405408
#### Unacknowledged results
406409

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
409412
[here](../crud/crud.md#write-results) to determine how to model unacknowledged results.
410413

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+
411417
#### Summary vs. verbose results
412418

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>;
415451

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.
424462

425463
#### Individual results
426464

@@ -871,6 +909,8 @@ batch-splitting to standardize implementations across drivers and simplify batch
871909

872910
## **Changelog**
873911

912+
- 2024-09-30: Define more options for modeling summary vs. verbose results.
913+
874914
- 2024-09-25: Add `collation` field to `update` document and clarify usage of `updateMods`.
875915

876916
- 2024-09-25: Update the `partialResult` population logic to account for ordered bulk writes.

0 commit comments

Comments
 (0)