@@ -23,7 +23,35 @@ export type RunCursorCommandOptions = {
23
23
* `maxTimeMS` is provided in the command in addition to setting `timeoutMS` in the options, then
24
24
* the original value of `maxTimeMS` will be overwritten. */
25
25
timeoutMS ?: number ;
26
- /** See {@link CursorTimeoutMode} */
26
+ /** @public
27
+ * Specifies how `timeoutMS` is applied to the cursor. Can be either `'cursorLifeTime'` or `'iteration'`
28
+ * When set to `'iteration'`, the deadline specified by `timeoutMS` applies to each call of
29
+ * `cursor.next()`.
30
+ * When set to `'cursorLifetime'`, the deadline applies to the life of the entire cursor.
31
+ *
32
+ * Depending on the type of cursor being used, this option has different default values.
33
+ * For non-tailable cursors, this value defaults to `'cursorLifetime'`
34
+ * For tailable cursors, this value defaults to `'iteration'` since tailable cursors, by
35
+ * definition can have an arbitrarily long lifetime.
36
+ *
37
+ * @example
38
+ * # Example showing use of `'iteration'`
39
+ * ```ts
40
+ * const cursor = collection.find({}, {timeoutMS: 100, timeoutMode: 'iteration'});
41
+ * for await (const doc of cursor) {
42
+ * // process doc
43
+ * // This will throw a timeout error if any of the iterator's `next()` calls takes more than 100ms, but
44
+ * will continue to iterate successfully otherwise, regardless of the number of batches.
45
+ * }
46
+ * ```
47
+ *
48
+ * # Example showing use of `'cursorLifetime'`
49
+ *
50
+ * ```ts
51
+ * const cursor = collection.find({}, { timeoutMS: 1000, timeoutMode: 'cursorLifetime' });
52
+ * const docs = await cursor.toArray(); // This entire line will throw a timeout error if all batches are not fetched and returned within 1000ms.
53
+ * ```
54
+ */
27
55
timeoutMode ?: CursorTimeoutMode ;
28
56
tailable ?: boolean ;
29
57
awaitData ?: boolean ;
0 commit comments