Skip to content

Commit 9acd138

Browse files
rnd 2
1 parent 07b7649 commit 9acd138

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

source/client-side-operations-timeout/client-side-operations-timeout.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,16 @@ check the command document for the presence of a `maxTimeMS` field.
427427

428428
See [runCommand behavior](#runcommand-behavior).
429429

430+
### Explain Helpers
431+
432+
If a driver provides an explain helper, drivers MUST take care to ensure that timeoutMS is correctly applied to the top-level
433+
explain command, when specified. Care should be taken by drivers with a fluent API - the following example
434+
should apply a timeoutMS of 1000 to the `explain` command:
435+
436+
```typescript
437+
collection.find({}, { timeoutMS: 1000 }).explain();
438+
```
439+
430440
## Test Plan
431441

432442
See the [README.rst](tests/README.md) in the tests directory.
@@ -650,6 +660,7 @@ timeout for each database operation. This would mimic using `timeoutMode=ITERATI
650660

651661
## Changelog
652662

663+
- 2024-08-23: Specify that explain helpers support support timeoutMS.
653664
- 2023-12-07: Migrated from reStructuredText to Markdown.
654665
- 2022-11-17: Use minimum RTT for maxTimeMS calculation instead of 90th percentile RTT.
655666
- 2022-10-05: Remove spec front matter.

source/crud/crud.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,6 +2198,26 @@ the [$readPreference global command argument](../message/OP_MSG.md#global-comman
21982198
[passing read preference to mongos and load balancers](../server-selection/server-selection.md#passing-read-preference-to-mongos-and-load-balancers)
21992199
(if applicable).
22002200

2201+
2202+
### Explain
2203+
2204+
Drivers MAY provide explain helpers. If a driver does provide explain helpers, the driver MUST ensure that its helper permits users to
2205+
specify maxTimeMS for the explain command specifically. An example, using Node, might look like:
2206+
2207+
```typescript
2208+
collection.find({ name: 'john doe' }).explain({ maxTimeMS: 1000 });
2209+
2210+
// sends:
2211+
{
2212+
explain: { find: <collection>, query: { name: 'john doe' } },
2213+
maxTimeMS: 1000
2214+
}
2215+
```
2216+
2217+
Drivers SHOULD be careful to
2218+
2219+
Drivers MUST document how users can specify options on their explain helpers.
2220+
22012221
## Test Plan
22022222

22032223
See the [README](tests/README.md) for tests.
@@ -2305,8 +2325,11 @@ unfortunate, we felt it better to have the bulk api be consistent with the rest
23052325
operations. However, the fluent-bulk-api is still able to be used as this change is non-backwards breaking. Any driver
23062326
which implemented the fluent bulk API should deprecate it and drivers that have not built it should not do so.
23072327

2308-
Q: What about explain?\
2309-
Explain has been determined to be not a normal use-case for a driver. We'd like users to use the
2328+
Q: Should drivers offer explain helpers?\
2329+
Originally, it was determined that explain should not be exposed via specialized APIs in drivers (runCommand was always an option after server 3.0.). However, some drivers historically have offered explain APIs and continue to do
2330+
so.
2331+
2332+
Explain helpers are not required because it has been determined to be not a normal use-case for a driver. We'd like users to use the
23102333
shell for this purpose. However, explain is still possible from a driver. For find, it can be passed as a modifier.
23112334
Aggregate can be run using a runCommand method passing the explain option. In addition, server 3.0 offers an explain
23122335
command that can be run using a runCommand method.
@@ -2369,6 +2392,8 @@ aforementioned allowance in the SemVer spec.
23692392

23702393
## Changelog
23712394

2395+
- 2024-08-23: Specify that explain helpers support maxTimeMS.
2396+
23722397
- 2024-02-20: Migrated from reStructuredText to Markdown.
23732398

23742399
- 2022-10-05: Remove spec front matter and reformat changelog.

source/crud/tests/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,3 +676,14 @@ InsertOne {
676676

677677
Execute `bulkWrite` on `client` with `model`. Assert that an error (referred to as `error`) is returned. Assert that
678678
`error` is a client error containing the message: "bulkWrite does not currently support automatic encryption".
679+
680+
### 14. `explain` helpers allow users to specify `maxTimeMS`
681+
682+
Create a MongoClient with command monitoring enabled (referred to as `client`).
683+
684+
Create a collection, referred to as `collection`, with the namespace `explain-test.collection`.
685+
686+
Run an explained find on `collection`. The find will have the query predicate `{ name: 'john doe' }`. Specify
687+
a maxTimeMS value of 2000ms for the `explain`.
688+
689+
Obtain the command started event for the explain. Confirm that the top-level explain command should has a `maxTimeMS` value of `2000`.

0 commit comments

Comments
 (0)