Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRIVERS-3036 Remove the BSON document size validation requirement for the client bulk write operation #1725

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions source/crud/bulk-write.md
Original file line number Diff line number Diff line change
Expand Up @@ -638,15 +638,10 @@ write concern containing the following message:

The server reports a `maxBsonObjectSize` in its `hello` response. This value defines the maximum size for documents that
are inserted into the database. Documents that are sent to the server but are not intended to be inserted into the
database (e.g. command documents) have a size limit of `maxBsonObjectSize + 16KiB`. When an acknowledged write concern
is used, drivers MUST NOT perform any checks related to these size limits and MUST rely on the server to raise an error
if a limit is exceeded. However, when an unacknowledged write concern is used, drivers MUST raise an error if one of the
following limits is exceeded:

- The size of a document to be inserted MUST NOT exceed `maxBsonObjectSize`. This applies to the `document` field of an
`InsertOneModel` and the `replacement` field of a `ReplaceOneModel`.
- The size of an entry in the `ops` array MUST NOT exceed `maxBsonObjectSize + 16KiB`.
- The size of the `bulkWrite` command document MUST NOT exceed `maxBsonObjectSize + 16KiB`.
database (e.g. command documents) have a size limit of `maxBsonObjectSize + 16KiB`. Clients MUST NOT validate the size
jyemin marked this conversation as resolved.
Show resolved Hide resolved
of BSON documents against these limits, and MUST rely on server validation, following the
["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)
mantra. For simplicity, this requirement remains in force even when a server acknowledgement is not expected.

See [SERVER-10643](https://jira.mongodb.org/browse/SERVER-10643) for more details on these size limits.

Expand Down Expand Up @@ -924,6 +919,8 @@ batch-splitting to standardize implementations across drivers and simplify batch

## **Changelog**

- 2024-11-05: Updated the requirements regarding the size validation.

- 2024-10-07: Error if `w:0` is used with `ordered=true` or `verboseResults=true`.

- 2024-10-01: Add sort option to `replaceOne` and `updateOne`.
Expand Down
47 changes: 3 additions & 44 deletions source/crud/tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -370,56 +370,15 @@ Assert that a CommandStartedEvent was observed for the `killCursors` command.

### 10. `MongoClient.bulkWrite` returns error for unacknowledged too-large insert
kevinAlbs marked this conversation as resolved.
Show resolved Hide resolved

This test must only be run on 8.0+ servers. This test must be skipped on Atlas Serverless.

Construct a `MongoClient` (referred to as `client`).

Perform a `hello` command using `client` and record the following values from the response: `maxBsonObjectSize`.

Then, construct the following document (referred to as `document`):

```javascript
{
"a": "b".repeat(maxBsonObjectSize)
}
```
Removed.

#### With insert

Construct the following write model (referred to as `model`):

```javascript
InsertOne: {
"namespace": "db.coll",
"document": document
}
```

Construct as list of write models (referred to as `models`) with the one `model`.

Call `MongoClient.bulkWrite` with `models`. Pass `BulkWriteOptions` with `ordered` set to `false` and `writeConcern` set
to an unacknowledged write concern.

Expect a client-side error due the size.
Removed.

#### With replace

Construct the following write model (referred to as `model`):

```javascript
ReplaceOne: {
"namespace": "db.coll",
"filter": {},
"replacement": document
}
```

Construct as list of write models (referred to as `models`) with the one `model`.

Call `MongoClient.bulkWrite` with `models`. Pass `BulkWriteOptions` with `ordered` set to `false` and `writeConcern` set
to an unacknowledged write concern.

Expect a client-side error due the size.
Removed.

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

Expand Down
Loading