You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: source/crud/bulk-write.md
+25-11Lines changed: 25 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -459,7 +459,7 @@ class BulkWriteResult {
459
459
* The results of each individual write operation that was successfully performed.
460
460
*
461
461
* This value will only be populated if the verboseResults option was set to true.
462
-
*/
462
+
*/
463
463
verboseResults:Optional<VerboseResults>;
464
464
465
465
/* rest of fields */
@@ -553,7 +553,9 @@ The `bulkWrite` server command has the following format:
553
553
}
554
554
```
555
555
556
-
Drivers MUST use document sequences ([`OP_MSG`](../message/OP_MSG.md) payload type 1) for the `ops` and `nsInfo` fields.
556
+
If auto-encryption is not enabled, drivers MUST use document sequences ([`OP_MSG`](../message/OP_MSG.md) payload type 1)
557
+
for the `ops` and `nsInfo` fields. If auto-encryption is enabled, drivers MUST NOT use document sequences and MUST
558
+
append the `ops` and `nsInfo` fields to the `bulkWrite` command document.
557
559
558
560
The `bulkWrite` command is executed on the "admin" database.
559
561
@@ -645,13 +647,6 @@ write concern containing the following message:
645
647
646
648
> Cannot request unacknowledged write concern and ordered writes
647
649
648
-
## Auto-Encryption
649
-
650
-
If `MongoClient.bulkWrite` is called on a `MongoClient` configured with `AutoEncryptionOpts`, drivers MUST return an
651
-
error with the message: "bulkWrite does not currently support automatic encryption".
652
-
653
-
This is expected to be removed once [DRIVERS-2888](https://jira.mongodb.org/browse/DRIVERS-2888) is implemented.
654
-
655
650
## Command Batching
656
651
657
652
Drivers MUST accept an arbitrary number of operations as input to the `MongoClient.bulkWrite` method. Because the server
@@ -672,8 +667,10 @@ multiple commands if the user provides more than `maxWriteBatchSize` operations
672
667
673
668
### Total Message Size
674
669
675
-
Drivers MUST ensure that the total size of the `OP_MSG` built for each `bulkWrite` command does not exceed
676
-
`maxMessageSizeBytes`.
670
+
#### Unencrypted bulk writes
671
+
672
+
When auto-encryption is not enabled, drivers MUST ensure that the total size of the `OP_MSG` built for each `bulkWrite`
673
+
command does not exceed `maxMessageSizeBytes`.
677
674
678
675
The upper bound for the size of an `OP_MSG` includes opcode-related bytes (e.g. the `OP_MSG` header) and
679
676
operation-agnostic command field bytes (e.g. `txnNumber`, `lsid`). Drivers MUST limit the combined size of the
@@ -727,6 +724,12 @@ was determined.
727
724
728
725
Drivers MUST return an error if there is not room to add at least one operation to `ops`.
729
726
727
+
#### Auto-encrypted bulk writes
728
+
729
+
Drivers MUST use the reduced size limit defined in
730
+
[Size limits for Write Commands](../client-side-encryption/client-side-encryption.md#size-limits-for-write-commands) for
731
+
the size of the `bulkWrite` command document when auto-encryption is enabled.
732
+
730
733
## Handling the `bulkWrite` Server Response
731
734
732
735
The server's response to `bulkWrite` has the following format:
@@ -857,6 +860,15 @@ When a `getMore` fails with a retryable error when attempting to iterate the res
857
860
entire `bulkWrite` command to receive a fresh cursor and retry iteration. This work was omitted to minimize the scope of
858
861
the initial implementation and testing of the new bulk write API, but may be revisited in the future.
859
862
863
+
### Use document sequences for auto-encrypted bulk writes
864
+
865
+
Auto-encryption does not currently support document sequences. This specification should be updated when
866
+
[DRIVERS-2859](https://jira.mongodb.org/browse/DRIVERS-2859) is completed to require use of document sequences for `ops`
867
+
and `nsInfo` when auto-encryption is enabled.
868
+
869
+
Drivers requiring significant changes to pass a bulkWrite command to libmongocrypt are recommended to wait until
870
+
[DRIVERS-2859](https://jira.mongodb.org/browse/DRIVERS-2859) is implemented before supporting automatic encryption.
871
+
860
872
## Q&A
861
873
862
874
### Is `bulkWrite` supported on Atlas Serverless?
@@ -928,6 +940,8 @@ error in this specific situation does not seem helpful enough to require size ch
928
940
929
941
## **Changelog**
930
942
943
+
- 2025-08-13: Removed the requirement to error when QE is enabled.
944
+
931
945
- 2025-06-27: Added `rawData` option.
932
946
933
947
- 2024-11-05: Updated the requirements regarding the size validation.
Copy file name to clipboardExpand all lines: source/crud/tests/README.md
+1-34Lines changed: 1 addition & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -607,40 +607,7 @@ Execute `bulkWrite` on `client` with `largeNamespaceModel`. Assert that an error
607
607
Assert that `error` is a client error. If a `BulkWriteException` was thrown, assert `BulkWriteException.partialResult`
608
608
is unset.
609
609
610
-
### 13. `MongoClient.bulkWrite` returns an error if auto-encryption is configured
611
-
612
-
This test is expected to be removed when [DRIVERS-2888](https://jira.mongodb.org/browse/DRIVERS-2888) is resolved.
613
-
614
-
Test that `MongoClient.bulkWrite` returns an error if the client has auto-encryption configured.
615
-
616
-
This test must only be run on 8.0+ servers. This test must be skipped on Atlas Serverless.
617
-
618
-
Construct a `MongoClient` (referred to as `client`) configured with the following `AutoEncryptionOpts`:
619
-
620
-
```javascript
621
-
AutoEncryptionOpts {
622
-
"keyVaultNamespace":"db.coll",
623
-
"kmsProviders": {
624
-
"aws": {
625
-
"accessKeyId":"foo",
626
-
"secretAccessKey":"bar"
627
-
}
628
-
}
629
-
}
630
-
```
631
-
632
-
Construct the following write model (referred to as `model`):
633
-
634
-
```javascript
635
-
InsertOne {
636
-
"namespace":"db.coll",
637
-
"document": { "a":"b" }
638
-
}
639
-
```
640
-
641
-
Execute `bulkWrite` on `client` with `model`. Assert that an error (referred to as `error`) is returned. Assert that
642
-
`error` is a client error containing the message: "bulkWrite does not currently support automatic encryption". If a
643
-
`BulkWriteException` was thrown, assert `BulkWriteException.partialResult` is unset.
610
+
### 13. *Removed*
644
611
645
612
### 14. `explain` helpers allow users to specify `maxTimeMS`
0 commit comments