@@ -104,6 +104,9 @@ Drivers MUST enforce timeouts for all operations per the
104
104
[ Client Side Operations Timeout] ( ../client-side-operations-timeout/client-side-operations-timeout.md ) specification. All
105
105
operations that return cursors MUST support the timeout options documented in the
106
106
[ Cursors] ( ../client-side-operations-timeout/client-side-operations-timeout.md#cursors ) section of that specification.
107
+ All explain helpers MUST support the timeout options documented in the
108
+ [ Explain Helpers] ( ../client-side-operations-timeout/client-side-operations-timeout.md#explain ) section of that
109
+ specification.
107
110
108
111
### API
109
112
@@ -178,9 +181,6 @@ interface Collection {
178
181
* as it would be impossible to be forwards and backwards compatible. Let the server
179
182
* handle the validation.
180
183
*
181
- * Note: If $explain is specified in the modifiers, the return value is a single
182
- * document. This could cause problems for static languages using strongly typed entities.
183
- *
184
184
* Note: result iteration should be backed by a cursor. Depending on the implementation,
185
185
* the cursor may back the returned Iterable instance or an iterator that it produces.
186
186
*
@@ -2201,6 +2201,47 @@ the [$readPreference global command argument](../message/OP_MSG.md#global-comman
2201
2201
[ passing read preference to mongos and load balancers] ( ../server-selection/server-selection.md#passing-read-preference-to-mongos-and-load-balancers )
2202
2202
(if applicable).
2203
2203
2204
+ ### Explain
2205
+
2206
+ > [ !NOTE]
2207
+ > Explain helpers are optional. Drivers that do not provide explain helpers may ignore this section.
2208
+
2209
+ ``` typescript
2210
+ interface ExplainOptions {
2211
+ /**
2212
+ * The maximum amount of time to allow the explain to run.
2213
+ *
2214
+ * This option is sent only if the caller explicitly provides a value. The default is to not send a value.
2215
+ *
2216
+ * NOTE: This option is deprecated in favor of timeoutMS.
2217
+ */
2218
+ maxTimeMS: Optional <Int64 >;
2219
+ }
2220
+ ```
2221
+
2222
+ Drivers MUST ensure that its helper permits users to specify a timeout (maxTimeMS or timeoutMS) for the explain command
2223
+ specifically. An example, using Node, might look like:
2224
+
2225
+ ``` typescript
2226
+ collection .find ({ name: ' john doe' }).explain ({ maxTimeMS: 1000 });
2227
+
2228
+ // sends:
2229
+ {
2230
+ explain : { find : <collection >, query : { name : ' john doe' } },
2231
+ maxTimeMS : 1000
2232
+ }
2233
+
2234
+ collection .find ({ name: ' john doe' }).explain ({ timeoutMS: 1000 });
2235
+
2236
+ // sends:
2237
+ {
2238
+ explain : { find : <collection >, query : { name : ' john doe' } },
2239
+ maxTimeMS : <1000 - min rtt >
2240
+ }
2241
+ ```
2242
+
2243
+ Drivers MUST document how users can specify options on their explain helpers.
2244
+
2204
2245
## Test Plan
2205
2246
2206
2247
See the [ README] ( tests/README.md ) for tests.
@@ -2313,6 +2354,13 @@ api be consistent with the rest of the methods in the CRUD family of operations.
2313
2354
able to be used as this change is non-backwards breaking. Any driver which implemented the fluent bulk API should
2314
2355
deprecate it and drivers that have not built it should not do so.
2315
2356
2357
+ Q: Should drivers offer explain helpers?\
2358
+ Originally, it was determined that explain should not be exposed via
2359
+ specialized APIs in drivers because it it was deemed to be an unusual use-case for a driver. We'd like users to use the
2360
+ shell for this purpose. However, explain is still possible from a driver. Some drivers have historically provided
2361
+ explain helpers and continue to do so. Drivers that do not offer explain helpers can run explain commands using the
2362
+ runCommand API.
2363
+
2316
2364
Q: What about explain?
2317
2365
2318
2366
Explain has been determined to be not a normal use-case for a driver. We'd like users to use the shell for this purpose.
@@ -2382,6 +2430,8 @@ aforementioned allowance in the SemVer spec.
2382
2430
2383
2431
## Changelog
2384
2432
2433
+ - 2024-09-12: Specify that explain helpers support maxTimeMS.
2434
+
2385
2435
- 2024-02-20: Migrated from reStructuredText to Markdown.
2386
2436
2387
2437
- 2022-10-05: Remove spec front matter and reformat changelog.
0 commit comments