Skip to content

Commit 3a4e2da

Browse files
authored
DRIVERS-3036 Remove the BSON document size validation requirement for the client bulk write operation (#1725)
1 parent fc7996d commit 3a4e2da

File tree

2 files changed

+14
-60
lines changed

2 files changed

+14
-60
lines changed

source/crud/bulk-write.md

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -634,22 +634,6 @@ write concern containing the following message:
634634

635635
> Cannot request unacknowledged write concern and ordered writes
636636
637-
### Size Limits
638-
639-
The server reports a `maxBsonObjectSize` in its `hello` response. This value defines the maximum size for documents that
640-
are inserted into the database. Documents that are sent to the server but are not intended to be inserted into the
641-
database (e.g. command documents) have a size limit of `maxBsonObjectSize + 16KiB`. When an acknowledged write concern
642-
is used, drivers MUST NOT perform any checks related to these size limits and MUST rely on the server to raise an error
643-
if a limit is exceeded. However, when an unacknowledged write concern is used, drivers MUST raise an error if one of the
644-
following limits is exceeded:
645-
646-
- The size of a document to be inserted MUST NOT exceed `maxBsonObjectSize`. This applies to the `document` field of an
647-
`InsertOneModel` and the `replacement` field of a `ReplaceOneModel`.
648-
- The size of an entry in the `ops` array MUST NOT exceed `maxBsonObjectSize + 16KiB`.
649-
- The size of the `bulkWrite` command document MUST NOT exceed `maxBsonObjectSize + 16KiB`.
650-
651-
See [SERVER-10643](https://jira.mongodb.org/browse/SERVER-10643) for more details on these size limits.
652-
653637
## Auto-Encryption
654638

655639
If `MongoClient.bulkWrite` is called on a `MongoClient` configured with `AutoEncryptionOpts`, drivers MUST return an
@@ -922,8 +906,19 @@ number was determined by constructing `OP_MSG` messages with various fields atta
922906
Drivers are required to use this value even if they are capable of determining the exact size of the message prior to
923907
batch-splitting to standardize implementations across drivers and simplify batch-splitting testing.
924908

909+
### Why is there no requirement to validate the size of a BSON document?
910+
911+
Following
912+
["_Where possible, depend on server to return errors_"](https://github.com/mongodb/specifications/blob/f8dbd2469f18d093f917efa1f758024bca5d3aaa/source/driver-mantras.md#where-possible-depend-on-server-to-return-errors),
913+
drivers should rely on the server to return errors about exceeded size limits. Such reliance is not possible for
914+
unacknowledged writes. This specification previously required drivers to check size limits for unacknowledged writes.
915+
The requirement has since been removed. Checking size limits complicates some driver implementations. Returning a driver
916+
error in this specific situation does not seem helpful enough to require size checks.
917+
925918
## **Changelog**
926919

920+
- 2024-11-05: Updated the requirements regarding the size validation.
921+
927922
- 2024-10-07: Error if `w:0` is used with `ordered=true` or `verboseResults=true`.
928923

929924
- 2024-10-01: Add sort option to `replaceOne` and `updateOne`.

source/crud/tests/README.md

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -370,56 +370,15 @@ Assert that a CommandStartedEvent was observed for the `killCursors` command.
370370

371371
### 10. `MongoClient.bulkWrite` returns error for unacknowledged too-large insert
372372

373-
This test must only be run on 8.0+ servers. This test must be skipped on Atlas Serverless.
374-
375-
Construct a `MongoClient` (referred to as `client`).
376-
377-
Perform a `hello` command using `client` and record the following values from the response: `maxBsonObjectSize`.
378-
379-
Then, construct the following document (referred to as `document`):
380-
381-
```javascript
382-
{
383-
"a": "b".repeat(maxBsonObjectSize)
384-
}
385-
```
373+
Removed.
386374

387375
#### With insert
388376

389-
Construct the following write model (referred to as `model`):
390-
391-
```javascript
392-
InsertOne: {
393-
"namespace": "db.coll",
394-
"document": document
395-
}
396-
```
397-
398-
Construct as list of write models (referred to as `models`) with the one `model`.
399-
400-
Call `MongoClient.bulkWrite` with `models`. Pass `BulkWriteOptions` with `ordered` set to `false` and `writeConcern` set
401-
to an unacknowledged write concern.
402-
403-
Expect a client-side error due the size.
377+
Removed.
404378

405379
#### With replace
406380

407-
Construct the following write model (referred to as `model`):
408-
409-
```javascript
410-
ReplaceOne: {
411-
"namespace": "db.coll",
412-
"filter": {},
413-
"replacement": document
414-
}
415-
```
416-
417-
Construct as list of write models (referred to as `models`) with the one `model`.
418-
419-
Call `MongoClient.bulkWrite` with `models`. Pass `BulkWriteOptions` with `ordered` set to `false` and `writeConcern` set
420-
to an unacknowledged write concern.
421-
422-
Expect a client-side error due the size.
381+
Removed.
423382

424383
### 11. `MongoClient.bulkWrite` batch splits when the addition of a new namespace exceeds the maximum message size
425384

0 commit comments

Comments
 (0)