mongodb 6.10.0 → 6.11.0-dev.20241128.sha.4842cd8a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (228) hide show
  1. package/README.md +2 -0
  2. package/lib/admin.js +3 -2
  3. package/lib/admin.js.map +1 -1
  4. package/lib/beta.d.ts +562 -45
  5. package/lib/bulk/common.js +4 -4
  6. package/lib/bulk/common.js.map +1 -1
  7. package/lib/change_stream.js +111 -51
  8. package/lib/change_stream.js.map +1 -1
  9. package/lib/client-side-encryption/auto_encrypter.js +8 -5
  10. package/lib/client-side-encryption/auto_encrypter.js.map +1 -1
  11. package/lib/client-side-encryption/client_encryption.js +48 -18
  12. package/lib/client-side-encryption/client_encryption.js.map +1 -1
  13. package/lib/client-side-encryption/state_machine.js +43 -29
  14. package/lib/client-side-encryption/state_machine.js.map +1 -1
  15. package/lib/cmap/auth/mongo_credentials.js +5 -2
  16. package/lib/cmap/auth/mongo_credentials.js.map +1 -1
  17. package/lib/cmap/auth/mongodb_aws.js +1 -1
  18. package/lib/cmap/auth/mongodb_aws.js.map +1 -1
  19. package/lib/cmap/auth/mongodb_oidc/k8s_machine_workflow.js +38 -0
  20. package/lib/cmap/auth/mongodb_oidc/k8s_machine_workflow.js.map +1 -0
  21. package/lib/cmap/auth/mongodb_oidc.js +2 -0
  22. package/lib/cmap/auth/mongodb_oidc.js.map +1 -1
  23. package/lib/cmap/connect.js +13 -1
  24. package/lib/cmap/connect.js.map +1 -1
  25. package/lib/cmap/connection.js +75 -17
  26. package/lib/cmap/connection.js.map +1 -1
  27. package/lib/cmap/connection_pool.js +14 -12
  28. package/lib/cmap/connection_pool.js.map +1 -1
  29. package/lib/cmap/wire_protocol/on_data.js +5 -1
  30. package/lib/cmap/wire_protocol/on_data.js.map +1 -1
  31. package/lib/cmap/wire_protocol/responses.js +30 -0
  32. package/lib/cmap/wire_protocol/responses.js.map +1 -1
  33. package/lib/collection.js +62 -3
  34. package/lib/collection.js.map +1 -1
  35. package/lib/connection_string.js +2 -0
  36. package/lib/connection_string.js.map +1 -1
  37. package/lib/cursor/abstract_cursor.js +221 -38
  38. package/lib/cursor/abstract_cursor.js.map +1 -1
  39. package/lib/cursor/aggregation_cursor.js +29 -7
  40. package/lib/cursor/aggregation_cursor.js.map +1 -1
  41. package/lib/cursor/change_stream_cursor.js +2 -2
  42. package/lib/cursor/change_stream_cursor.js.map +1 -1
  43. package/lib/cursor/client_bulk_write_cursor.js +1 -1
  44. package/lib/cursor/client_bulk_write_cursor.js.map +1 -1
  45. package/lib/cursor/find_cursor.js +18 -8
  46. package/lib/cursor/find_cursor.js.map +1 -1
  47. package/lib/cursor/list_collections_cursor.js +1 -1
  48. package/lib/cursor/list_collections_cursor.js.map +1 -1
  49. package/lib/cursor/list_indexes_cursor.js +1 -1
  50. package/lib/cursor/list_indexes_cursor.js.map +1 -1
  51. package/lib/cursor/run_command_cursor.js +6 -4
  52. package/lib/cursor/run_command_cursor.js.map +1 -1
  53. package/lib/db.js +63 -3
  54. package/lib/db.js.map +1 -1
  55. package/lib/error.js +34 -9
  56. package/lib/error.js.map +1 -1
  57. package/lib/explain.js +57 -1
  58. package/lib/explain.js.map +1 -1
  59. package/lib/gridfs/download.js +31 -3
  60. package/lib/gridfs/download.js.map +1 -1
  61. package/lib/gridfs/index.js +49 -14
  62. package/lib/gridfs/index.js.map +1 -1
  63. package/lib/gridfs/upload.js +80 -22
  64. package/lib/gridfs/upload.js.map +1 -1
  65. package/lib/index.js +9 -5
  66. package/lib/index.js.map +1 -1
  67. package/lib/mongo_client.js +70 -1
  68. package/lib/mongo_client.js.map +1 -1
  69. package/lib/operations/aggregate.js +2 -2
  70. package/lib/operations/aggregate.js.map +1 -1
  71. package/lib/operations/bulk_write.js +7 -2
  72. package/lib/operations/bulk_write.js.map +1 -1
  73. package/lib/operations/client_bulk_write/client_bulk_write.js +3 -3
  74. package/lib/operations/client_bulk_write/client_bulk_write.js.map +1 -1
  75. package/lib/operations/client_bulk_write/executor.js +14 -3
  76. package/lib/operations/client_bulk_write/executor.js.map +1 -1
  77. package/lib/operations/command.js +5 -2
  78. package/lib/operations/command.js.map +1 -1
  79. package/lib/operations/count.js +2 -2
  80. package/lib/operations/count.js.map +1 -1
  81. package/lib/operations/create_collection.js +8 -7
  82. package/lib/operations/create_collection.js.map +1 -1
  83. package/lib/operations/delete.js +6 -6
  84. package/lib/operations/delete.js.map +1 -1
  85. package/lib/operations/distinct.js +2 -2
  86. package/lib/operations/distinct.js.map +1 -1
  87. package/lib/operations/drop.js +8 -8
  88. package/lib/operations/drop.js.map +1 -1
  89. package/lib/operations/estimated_document_count.js +2 -2
  90. package/lib/operations/estimated_document_count.js.map +1 -1
  91. package/lib/operations/execute_operation.js +16 -10
  92. package/lib/operations/execute_operation.js.map +1 -1
  93. package/lib/operations/find.js +6 -3
  94. package/lib/operations/find.js.map +1 -1
  95. package/lib/operations/find_and_modify.js +2 -2
  96. package/lib/operations/find_and_modify.js.map +1 -1
  97. package/lib/operations/get_more.js +2 -1
  98. package/lib/operations/get_more.js.map +1 -1
  99. package/lib/operations/indexes.js +6 -6
  100. package/lib/operations/indexes.js.map +1 -1
  101. package/lib/operations/insert.js +6 -6
  102. package/lib/operations/insert.js.map +1 -1
  103. package/lib/operations/kill_cursors.js +5 -2
  104. package/lib/operations/kill_cursors.js.map +1 -1
  105. package/lib/operations/list_collections.js +2 -2
  106. package/lib/operations/list_collections.js.map +1 -1
  107. package/lib/operations/list_databases.js +2 -2
  108. package/lib/operations/list_databases.js.map +1 -1
  109. package/lib/operations/operation.js.map +1 -1
  110. package/lib/operations/profiling_level.js +2 -2
  111. package/lib/operations/profiling_level.js.map +1 -1
  112. package/lib/operations/remove_user.js +2 -2
  113. package/lib/operations/remove_user.js.map +1 -1
  114. package/lib/operations/rename.js +2 -2
  115. package/lib/operations/rename.js.map +1 -1
  116. package/lib/operations/run_command.js +6 -4
  117. package/lib/operations/run_command.js.map +1 -1
  118. package/lib/operations/search_indexes/create.js +5 -2
  119. package/lib/operations/search_indexes/create.js.map +1 -1
  120. package/lib/operations/search_indexes/drop.js +2 -2
  121. package/lib/operations/search_indexes/drop.js.map +1 -1
  122. package/lib/operations/search_indexes/update.js +2 -2
  123. package/lib/operations/search_indexes/update.js.map +1 -1
  124. package/lib/operations/set_profiling_level.js +2 -2
  125. package/lib/operations/set_profiling_level.js.map +1 -1
  126. package/lib/operations/stats.js +2 -2
  127. package/lib/operations/stats.js.map +1 -1
  128. package/lib/operations/update.js +8 -8
  129. package/lib/operations/update.js.map +1 -1
  130. package/lib/operations/validate_collection.js +2 -2
  131. package/lib/operations/validate_collection.js.map +1 -1
  132. package/lib/read_concern.js +1 -1
  133. package/lib/sdam/common.js +0 -7
  134. package/lib/sdam/common.js.map +1 -1
  135. package/lib/sdam/server.js +4 -1
  136. package/lib/sdam/server.js.map +1 -1
  137. package/lib/sdam/server_description.js +4 -2
  138. package/lib/sdam/server_description.js.map +1 -1
  139. package/lib/sdam/server_selection.js +5 -2
  140. package/lib/sdam/server_selection.js.map +1 -1
  141. package/lib/sdam/topology.js +38 -15
  142. package/lib/sdam/topology.js.map +1 -1
  143. package/lib/sessions.js +157 -98
  144. package/lib/sessions.js.map +1 -1
  145. package/lib/timeout.js +231 -16
  146. package/lib/timeout.js.map +1 -1
  147. package/lib/utils.js +36 -19
  148. package/lib/utils.js.map +1 -1
  149. package/lib/write_concern.js.map +1 -1
  150. package/mongodb.d.ts +562 -45
  151. package/package.json +18 -17
  152. package/src/admin.ts +6 -2
  153. package/src/bulk/common.ts +17 -5
  154. package/src/change_stream.ts +127 -52
  155. package/src/client-side-encryption/auto_encrypter.ts +12 -5
  156. package/src/client-side-encryption/client_encryption.ts +103 -20
  157. package/src/client-side-encryption/state_machine.ts +66 -32
  158. package/src/cmap/auth/mongo_credentials.ts +6 -3
  159. package/src/cmap/auth/mongodb_aws.ts +1 -1
  160. package/src/cmap/auth/mongodb_oidc/k8s_machine_workflow.ts +38 -0
  161. package/src/cmap/auth/mongodb_oidc.ts +3 -1
  162. package/src/cmap/connect.ts +18 -1
  163. package/src/cmap/connection.ts +105 -17
  164. package/src/cmap/connection_pool.ts +15 -17
  165. package/src/cmap/handshake/client_metadata.ts +1 -1
  166. package/src/cmap/wire_protocol/on_data.ts +11 -1
  167. package/src/cmap/wire_protocol/responses.ts +35 -1
  168. package/src/collection.ts +81 -9
  169. package/src/connection_string.ts +2 -0
  170. package/src/cursor/abstract_cursor.ts +287 -39
  171. package/src/cursor/aggregation_cursor.ts +54 -8
  172. package/src/cursor/change_stream_cursor.ts +6 -2
  173. package/src/cursor/client_bulk_write_cursor.ts +6 -2
  174. package/src/cursor/find_cursor.ts +40 -9
  175. package/src/cursor/list_collections_cursor.ts +1 -1
  176. package/src/cursor/list_indexes_cursor.ts +1 -1
  177. package/src/cursor/run_command_cursor.ts +50 -5
  178. package/src/db.ts +75 -7
  179. package/src/error.ts +33 -8
  180. package/src/explain.ts +85 -0
  181. package/src/gridfs/download.ts +43 -4
  182. package/src/gridfs/index.ts +64 -16
  183. package/src/gridfs/upload.ts +153 -45
  184. package/src/index.ts +27 -5
  185. package/src/mongo_client.ts +76 -4
  186. package/src/operations/aggregate.ts +10 -2
  187. package/src/operations/bulk_write.ts +9 -2
  188. package/src/operations/client_bulk_write/client_bulk_write.ts +11 -3
  189. package/src/operations/client_bulk_write/executor.ts +15 -3
  190. package/src/operations/command.ts +18 -8
  191. package/src/operations/count.ts +10 -3
  192. package/src/operations/create_collection.ts +14 -7
  193. package/src/operations/delete.ts +15 -6
  194. package/src/operations/distinct.ts +7 -2
  195. package/src/operations/drop.ts +18 -8
  196. package/src/operations/estimated_document_count.ts +7 -2
  197. package/src/operations/execute_operation.ts +22 -13
  198. package/src/operations/find.ts +17 -5
  199. package/src/operations/find_and_modify.ts +7 -2
  200. package/src/operations/get_more.ts +4 -1
  201. package/src/operations/indexes.ts +20 -7
  202. package/src/operations/insert.ts +13 -6
  203. package/src/operations/kill_cursors.ts +10 -2
  204. package/src/operations/list_collections.ts +10 -1
  205. package/src/operations/list_databases.ts +9 -2
  206. package/src/operations/operation.ts +16 -2
  207. package/src/operations/profiling_level.ts +7 -2
  208. package/src/operations/remove_user.ts +7 -2
  209. package/src/operations/rename.ts +7 -2
  210. package/src/operations/run_command.ts +23 -4
  211. package/src/operations/search_indexes/create.ts +10 -2
  212. package/src/operations/search_indexes/drop.ts +7 -2
  213. package/src/operations/search_indexes/update.ts +7 -2
  214. package/src/operations/set_profiling_level.ts +4 -2
  215. package/src/operations/stats.ts +7 -2
  216. package/src/operations/update.ts +16 -8
  217. package/src/operations/validate_collection.ts +7 -2
  218. package/src/read_concern.ts +1 -1
  219. package/src/sdam/common.ts +0 -11
  220. package/src/sdam/server.ts +14 -4
  221. package/src/sdam/server_description.ts +6 -2
  222. package/src/sdam/server_selection.ts +5 -2
  223. package/src/sdam/topology.ts +43 -27
  224. package/src/sessions.ts +206 -120
  225. package/src/timeout.ts +327 -23
  226. package/src/transactions.ts +1 -1
  227. package/src/utils.ts +47 -30
  228. package/src/write_concern.ts +6 -3
package/mongodb.d.ts CHANGED
@@ -43,6 +43,7 @@ export declare abstract class AbstractCursor<TSchema = any, CursorEvents extends
43
43
  /* Excluded from this release type: isClosed */
44
44
  /* Excluded from this release type: isKilled */
45
45
  /* Excluded from this release type: cursorOptions */
46
+ /* Excluded from this release type: timeoutContext */
46
47
  /** @event */
47
48
  static readonly CLOSE: "close";
48
49
  /* Excluded from this release type: deserializationOptions */
@@ -100,7 +101,9 @@ export declare abstract class AbstractCursor<TSchema = any, CursorEvents extends
100
101
  /**
101
102
  * Frees any client-side resources used by the cursor.
102
103
  */
103
- close(): Promise<void>;
104
+ close(options?: {
105
+ timeoutMS?: number;
106
+ }): Promise<void>;
104
107
  /**
105
108
  * Returns an array of documents. The caller is responsible for making sure that there
106
109
  * is enough memory to store the results. Note that the array only contains partial
@@ -251,7 +254,39 @@ export declare interface AbstractCursorOptions extends BSONSerializeOptions {
251
254
  */
252
255
  awaitData?: boolean;
253
256
  noCursorTimeout?: boolean;
254
- /* Excluded from this release type: timeoutMS */
257
+ /** Specifies the time an operation will run until it throws a timeout error. See {@link AbstractCursorOptions.timeoutMode} for more details on how this option applies to cursors. */
258
+ timeoutMS?: number;
259
+ /**
260
+ * @public
261
+ * @experimental
262
+ * Specifies how `timeoutMS` is applied to the cursor. Can be either `'cursorLifeTime'` or `'iteration'`
263
+ * When set to `'iteration'`, the deadline specified by `timeoutMS` applies to each call of
264
+ * `cursor.next()`.
265
+ * When set to `'cursorLifetime'`, the deadline applies to the life of the entire cursor.
266
+ *
267
+ * Depending on the type of cursor being used, this option has different default values.
268
+ * For non-tailable cursors, this value defaults to `'cursorLifetime'`
269
+ * For tailable cursors, this value defaults to `'iteration'` since tailable cursors, by
270
+ * definition can have an arbitrarily long lifetime.
271
+ *
272
+ * @example
273
+ * ```ts
274
+ * const cursor = collection.find({}, {timeoutMS: 100, timeoutMode: 'iteration'});
275
+ * for await (const doc of cursor) {
276
+ * // process doc
277
+ * // This will throw a timeout error if any of the iterator's `next()` calls takes more than 100ms, but
278
+ * // will continue to iterate successfully otherwise, regardless of the number of batches.
279
+ * }
280
+ * ```
281
+ *
282
+ * @example
283
+ * ```ts
284
+ * const cursor = collection.find({}, { timeoutMS: 1000, timeoutMode: 'cursorLifetime' });
285
+ * const docs = await cursor.toArray(); // This entire line will throw a timeout error if all batches are not fetched and returned within 1000ms.
286
+ * ```
287
+ */
288
+ timeoutMode?: CursorTimeoutMode;
289
+ /* Excluded from this release type: timeoutContext */
255
290
  }
256
291
 
257
292
  /* Excluded from this release type: AbstractOperation */
@@ -377,7 +412,9 @@ export declare interface AggregateOptions extends Omit<CommandOperationOptions,
377
412
  bypassDocumentValidation?: boolean;
378
413
  /** Return the query as cursor, on 2.6 \> it returns as a real cursor on pre 2.6 it returns as an emulated cursor. */
379
414
  cursor?: Document;
380
- /** specifies a cumulative time limit in milliseconds for processing operations on the cursor. MongoDB interrupts the operation at the earliest following interrupt point. */
415
+ /**
416
+ * Specifies a cumulative time limit in milliseconds for processing operations on the cursor. MongoDB interrupts the operation at the earliest following interrupt point.
417
+ */
381
418
  maxTimeMS?: number;
382
419
  /** The maximum amount of time for the server to wait on new documents to satisfy a tailable cursor query. */
383
420
  maxAwaitTimeMS?: number;
@@ -394,6 +431,7 @@ export declare interface AggregateOptions extends Omit<CommandOperationOptions,
394
431
  * or `db.aggregate().explain()`.
395
432
  */
396
433
  explain?: ExplainOptions['explain'];
434
+ /* Excluded from this release type: timeoutMode */
397
435
  }
398
436
 
399
437
  /**
@@ -403,7 +441,7 @@ export declare interface AggregateOptions extends Omit<CommandOperationOptions,
403
441
  * or higher stream
404
442
  * @public
405
443
  */
406
- export declare class AggregationCursor<TSchema = any> extends AbstractCursor<TSchema> {
444
+ export declare class AggregationCursor<TSchema = any> extends ExplainableCursor<TSchema> {
407
445
  readonly pipeline: Document[];
408
446
  /* Excluded from this release type: aggregateOptions */
409
447
  /* Excluded from this release type: __constructor */
@@ -411,7 +449,14 @@ export declare class AggregationCursor<TSchema = any> extends AbstractCursor<TSc
411
449
  map<T>(transform: (doc: TSchema) => T): AggregationCursor<T>;
412
450
  /* Excluded from this release type: _initialize */
413
451
  /** Execute the explain for the cursor */
414
- explain(verbosity?: ExplainVerbosityLike | ExplainCommandOptions): Promise<Document>;
452
+ explain(): Promise<Document>;
453
+ explain(verbosity: ExplainVerbosityLike | ExplainCommandOptions): Promise<Document>;
454
+ explain(options: {
455
+ timeoutMS?: number;
456
+ }): Promise<Document>;
457
+ explain(verbosity: ExplainVerbosityLike | ExplainCommandOptions, options: {
458
+ timeoutMS?: number;
459
+ }): Promise<Document>;
415
460
  /** Add a stage to the aggregation pipeline
416
461
  * @example
417
462
  * ```
@@ -588,7 +633,7 @@ export declare interface AuthMechanismProperties extends Document {
588
633
  /** A user provided OIDC human interacted callback function. */
589
634
  OIDC_HUMAN_CALLBACK?: OIDCCallbackFunction;
590
635
  /** The OIDC environment. Note that 'test' is for internal use only. */
591
- ENVIRONMENT?: 'test' | 'azure' | 'gcp';
636
+ ENVIRONMENT?: 'test' | 'azure' | 'gcp' | 'k8s';
592
637
  /** Allowed hosts that OIDC auth can connect to. */
593
638
  ALLOWED_HOSTS?: string[];
594
639
  /** The resource token for OIDC auth in Azure and GCP. */
@@ -973,6 +1018,7 @@ export declare interface BulkWriteOptions extends CommandOperationOptions {
973
1018
  forceServerObjectId?: boolean;
974
1019
  /** Map of parameter names and values that can be accessed using $$var (requires MongoDB 5.0). */
975
1020
  let?: Document;
1021
+ /* Excluded from this release type: timeoutContext */
976
1022
  }
977
1023
 
978
1024
  /**
@@ -1084,6 +1130,13 @@ export declare class ChangeStream<TSchema extends Document = Document, TChange e
1084
1130
  * @event
1085
1131
  */
1086
1132
  static readonly RESUME_TOKEN_CHANGED: "resumeTokenChanged";
1133
+ private timeoutContext?;
1134
+ /**
1135
+ * Note that this property is here to uniquely identify a ChangeStream instance as the owner of
1136
+ * the {@link CursorTimeoutContext} instance (see {@link ChangeStream._createChangeStreamCursor}) to ensure
1137
+ * that {@link AbstractCursor.close} does not mutate the timeoutContext.
1138
+ */
1139
+ private contextOwner;
1087
1140
  /* Excluded from this release type: __constructor */
1088
1141
  /* Excluded from this release type: cursorStream */
1089
1142
  /** The cached resume token that is used to resume after the most recently returned change. */
@@ -1121,6 +1174,7 @@ export declare class ChangeStream<TSchema extends Document = Document, TChange e
1121
1174
  /* Excluded from this release type: _processChange */
1122
1175
  /* Excluded from this release type: _processErrorStreamMode */
1123
1176
  /* Excluded from this release type: _processErrorIteratorMode */
1177
+ private _resume;
1124
1178
  }
1125
1179
 
1126
1180
  /**
@@ -1296,7 +1350,14 @@ export declare type ChangeStreamEvents<TSchema extends Document = Document, TCha
1296
1350
  end(): void;
1297
1351
  error(error: Error): void;
1298
1352
  change(change: TChange): void;
1299
- } & AbstractCursorEvents;
1353
+ /**
1354
+ * @remarks Note that the `close` event is currently emitted whenever the internal `ChangeStreamCursor`
1355
+ * instance is closed, which can occur multiple times for a given `ChangeStream` instance.
1356
+ *
1357
+ * TODO(NODE-6434): address this issue in NODE-6434
1358
+ */
1359
+ close(): void;
1360
+ };
1300
1361
 
1301
1362
  /**
1302
1363
  * @public
@@ -1635,6 +1696,7 @@ export declare class ClientEncryption {
1635
1696
  /* Excluded from this release type: _proxyOptions */
1636
1697
  /* Excluded from this release type: _tlsOptions */
1637
1698
  /* Excluded from this release type: _kmsProviders */
1699
+ /* Excluded from this release type: _timeoutMS */
1638
1700
  /* Excluded from this release type: _mongoCrypt */
1639
1701
  /* Excluded from this release type: getMongoCrypt */
1640
1702
  /**
@@ -1938,6 +2000,7 @@ export declare interface ClientEncryptionCreateDataKeyProviderOptions {
1938
2000
  keyAltNames?: string[] | undefined;
1939
2001
  /** @experimental */
1940
2002
  keyMaterial?: Buffer | Binary;
2003
+ /* Excluded from this release type: timeoutContext */
1941
2004
  }
1942
2005
 
1943
2006
  /**
@@ -2004,6 +2067,38 @@ export declare interface ClientEncryptionOptions {
2004
2067
  * TLS options for kms providers to use.
2005
2068
  */
2006
2069
  tlsOptions?: CSFLEKMSTlsOptions;
2070
+ /**
2071
+ * @experimental
2072
+ *
2073
+ * The timeout setting to be used for all the operations on ClientEncryption.
2074
+ *
2075
+ * When provided, `timeoutMS` is used as the timeout for each operation executed on
2076
+ * the ClientEncryption object. For example:
2077
+ *
2078
+ * ```typescript
2079
+ * const clientEncryption = new ClientEncryption(client, {
2080
+ * timeoutMS: 1_000
2081
+ * kmsProviders: { local: { key: '<KEY>' } }
2082
+ * });
2083
+ *
2084
+ * // `1_000` is used as the timeout for createDataKey call
2085
+ * await clientEncryption.createDataKey('local');
2086
+ * ```
2087
+ *
2088
+ * If `timeoutMS` is configured on the provided client, the client's `timeoutMS` value
2089
+ * will be used unless `timeoutMS` is also provided as a client encryption option.
2090
+ *
2091
+ * ```typescript
2092
+ * const client = new MongoClient('<uri>', { timeoutMS: 2_000 });
2093
+ *
2094
+ * // timeoutMS is set to 1_000 on clientEncryption
2095
+ * const clientEncryption = new ClientEncryption(client, {
2096
+ * timeoutMS: 1_000
2097
+ * kmsProviders: { local: { key: '<KEY>' } }
2098
+ * });
2099
+ * ```
2100
+ */
2101
+ timeoutMS?: number;
2007
2102
  }
2008
2103
 
2009
2104
  /**
@@ -2062,7 +2157,7 @@ export declare interface ClientInsertOneResult {
2062
2157
 
2063
2158
  /**
2064
2159
  * @public
2065
- * @see https://github.com/mongodb/specifications/blob/master/source/mongodb-handshake/handshake.rst#hello-command
2160
+ * @see https://github.com/mongodb/specifications/blob/master/source/mongodb-handshake/handshake.md#hello-command
2066
2161
  */
2067
2162
  export declare interface ClientMetadata {
2068
2163
  driver: {
@@ -2127,7 +2222,7 @@ export declare class ClientSession extends TypedEventEmitter<ClientSessionEvents
2127
2222
  /* Excluded from this release type: client */
2128
2223
  /* Excluded from this release type: sessionPool */
2129
2224
  hasEnded: boolean;
2130
- clientOptions?: MongoOptions;
2225
+ clientOptions: MongoOptions;
2131
2226
  supports: {
2132
2227
  causalConsistency: boolean;
2133
2228
  };
@@ -2143,7 +2238,12 @@ export declare class ClientSession extends TypedEventEmitter<ClientSessionEvents
2143
2238
  /* Excluded from this release type: [kSnapshotEnabled] */
2144
2239
  /* Excluded from this release type: [kPinnedConnection] */
2145
2240
  /* Excluded from this release type: [kTxnNumberIncrement] */
2146
- /* Excluded from this release type: timeoutMS */
2241
+ /**
2242
+ * @experimental
2243
+ * Specifies the time an operation in a given `ClientSession` will run until it throws a timeout error
2244
+ */
2245
+ timeoutMS?: number;
2246
+ /* Excluded from this release type: timeoutContext */
2147
2247
  /* Excluded from this release type: __constructor */
2148
2248
  /** The server id associated with this session */
2149
2249
  get id(): ServerSessionId | undefined;
@@ -2208,12 +2308,21 @@ export declare class ClientSession extends TypedEventEmitter<ClientSessionEvents
2208
2308
  startTransaction(options?: TransactionOptions): void;
2209
2309
  /**
2210
2310
  * Commits the currently active transaction in this session.
2311
+ *
2312
+ * @param options - Optional options, can be used to override `defaultTimeoutMS`.
2211
2313
  */
2212
- commitTransaction(): Promise<void>;
2314
+ commitTransaction(options?: {
2315
+ timeoutMS?: number;
2316
+ }): Promise<void>;
2213
2317
  /**
2214
2318
  * Aborts the currently active transaction in this session.
2319
+ *
2320
+ * @param options - Optional options, can be used to override `defaultTimeoutMS`.
2215
2321
  */
2216
- abortTransaction(): Promise<void>;
2322
+ abortTransaction(options?: {
2323
+ timeoutMS?: number;
2324
+ }): Promise<void>;
2325
+ /* Excluded from this release type: abortTransaction */
2217
2326
  /**
2218
2327
  * This is here to ensure that ClientSession is never serialized to BSON.
2219
2328
  */
@@ -2227,6 +2336,9 @@ export declare class ClientSession extends TypedEventEmitter<ClientSessionEvents
2227
2336
  * `Promise.allSettled`, `Promise.race`, etc to parallelize operations inside a transaction is
2228
2337
  * undefined behaviour.
2229
2338
  *
2339
+ * **IMPORTANT:** When running an operation inside a `withTransaction` callback, if it is not
2340
+ * provided the explicit session in its options, it will not be part of the transaction and it will not respect timeoutMS.
2341
+ *
2230
2342
  *
2231
2343
  * @remarks
2232
2344
  * - If all operations successfully complete and the `commitTransaction` operation is successful, then the provided function will return the result of the provided function.
@@ -2250,7 +2362,16 @@ export declare class ClientSession extends TypedEventEmitter<ClientSessionEvents
2250
2362
  * @param options - optional settings for the transaction
2251
2363
  * @returns A raw command response or undefined
2252
2364
  */
2253
- withTransaction<T = any>(fn: WithTransactionCallback<T>, options?: TransactionOptions): Promise<T>;
2365
+ withTransaction<T = any>(fn: WithTransactionCallback<T>, options?: TransactionOptions & {
2366
+ /**
2367
+ * Configures a timeoutMS expiry for the entire withTransactionCallback.
2368
+ *
2369
+ * @remarks
2370
+ * - The remaining timeout will not be applied to callback operations that do not use the ClientSession.
2371
+ * - Overriding timeoutMS for operations executed using the explicit session inside the provided callback will result in a client-side error.
2372
+ */
2373
+ timeoutMS?: number;
2374
+ }): Promise<T>;
2254
2375
  }
2255
2376
 
2256
2377
  /** @public */
@@ -2266,7 +2387,13 @@ export declare interface ClientSessionOptions {
2266
2387
  snapshot?: boolean;
2267
2388
  /** The default TransactionOptions to use for transactions started on this session. */
2268
2389
  defaultTransactionOptions?: TransactionOptions;
2269
- /* Excluded from this release type: defaultTimeoutMS */
2390
+ /**
2391
+ * @public
2392
+ * @experimental
2393
+ * An overriding timeoutMS value to use for a client-side timeout.
2394
+ * If not provided the session uses the timeoutMS specified on the MongoClient.
2395
+ */
2396
+ defaultTimeoutMS?: number;
2270
2397
  /* Excluded from this release type: owner */
2271
2398
  /* Excluded from this release type: explicit */
2272
2399
  /* Excluded from this release type: initialClusterTime */
@@ -2468,6 +2595,7 @@ export declare class Collection<TSchema extends Document = Document> {
2468
2595
  /** The current index hint for the collection */
2469
2596
  get hint(): Hint | undefined;
2470
2597
  set hint(v: Hint | undefined);
2598
+ get timeoutMS(): number | undefined;
2471
2599
  /**
2472
2600
  * Inserts a single document into MongoDB. If documents passed in do not contain the **_id** field,
2473
2601
  * one will be added to each of the documents missing it by the driver, mutating the document. This behavior
@@ -2576,10 +2704,10 @@ export declare class Collection<TSchema extends Document = Document> {
2576
2704
  */
2577
2705
  findOne(): Promise<WithId<TSchema> | null>;
2578
2706
  findOne(filter: Filter<TSchema>): Promise<WithId<TSchema> | null>;
2579
- findOne(filter: Filter<TSchema>, options: FindOptions): Promise<WithId<TSchema> | null>;
2707
+ findOne(filter: Filter<TSchema>, options: Omit<FindOptions, 'timeoutMode'>): Promise<WithId<TSchema> | null>;
2580
2708
  findOne<T = TSchema>(): Promise<T | null>;
2581
2709
  findOne<T = TSchema>(filter: Filter<TSchema>): Promise<T | null>;
2582
- findOne<T = TSchema>(filter: Filter<TSchema>, options?: FindOptions): Promise<T | null>;
2710
+ findOne<T = TSchema>(filter: Filter<TSchema>, options?: Omit<FindOptions, 'timeoutMode'>): Promise<T | null>;
2583
2711
  /**
2584
2712
  * Creates a cursor for a filter that can be used to iterate over results from MongoDB
2585
2713
  *
@@ -2850,6 +2978,59 @@ export declare class Collection<TSchema extends Document = Document> {
2850
2978
  * });
2851
2979
  * ```
2852
2980
  *
2981
+ * @remarks
2982
+ * When `timeoutMS` is configured for a change stream, it will have different behaviour depending
2983
+ * on whether the change stream is in iterator mode or emitter mode. In both cases, a change
2984
+ * stream will time out if it does not receive a change event within `timeoutMS` of the last change
2985
+ * event.
2986
+ *
2987
+ * Note that if a change stream is consistently timing out when watching a collection, database or
2988
+ * client that is being changed, then this may be due to the server timing out before it can finish
2989
+ * processing the existing oplog. To address this, restart the change stream with a higher
2990
+ * `timeoutMS`.
2991
+ *
2992
+ * If the change stream times out the initial aggregate operation to establish the change stream on
2993
+ * the server, then the client will close the change stream. If the getMore calls to the server
2994
+ * time out, then the change stream will be left open, but will throw a MongoOperationTimeoutError
2995
+ * when in iterator mode and emit an error event that returns a MongoOperationTimeoutError in
2996
+ * emitter mode.
2997
+ *
2998
+ * To determine whether or not the change stream is still open following a timeout, check the
2999
+ * {@link ChangeStream.closed} getter.
3000
+ *
3001
+ * @example
3002
+ * In iterator mode, if a next() call throws a timeout error, it will attempt to resume the change stream.
3003
+ * The next call can just be retried after this succeeds.
3004
+ * ```ts
3005
+ * const changeStream = collection.watch([], { timeoutMS: 100 });
3006
+ * try {
3007
+ * await changeStream.next();
3008
+ * } catch (e) {
3009
+ * if (e instanceof MongoOperationTimeoutError && !changeStream.closed) {
3010
+ * await changeStream.next();
3011
+ * }
3012
+ * throw e;
3013
+ * }
3014
+ * ```
3015
+ *
3016
+ * @example
3017
+ * In emitter mode, if the change stream goes `timeoutMS` without emitting a change event, it will
3018
+ * emit an error event that returns a MongoOperationTimeoutError, but will not close the change
3019
+ * stream unless the resume attempt fails. There is no need to re-establish change listeners as
3020
+ * this will automatically continue emitting change events once the resume attempt completes.
3021
+ *
3022
+ * ```ts
3023
+ * const changeStream = collection.watch([], { timeoutMS: 100 });
3024
+ * changeStream.on('change', console.log);
3025
+ * changeStream.on('error', e => {
3026
+ * if (e instanceof MongoOperationTimeoutError && !changeStream.closed) {
3027
+ * // do nothing
3028
+ * } else {
3029
+ * changeStream.close();
3030
+ * }
3031
+ * });
3032
+ * ```
3033
+ *
2853
3034
  * @param pipeline - An array of {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation-pipeline/|aggregation pipeline stages} through which to pass change stream documents. This allows for filtering (using $match) and manipulating the change stream documents.
2854
3035
  * @param options - Optional settings for the command
2855
3036
  * @typeParam TLocal - Type of the data being detected by the change stream
@@ -2960,7 +3141,11 @@ export declare interface CollectionOptions extends BSONSerializeOptions, WriteCo
2960
3141
  readConcern?: ReadConcernLike;
2961
3142
  /** The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST). */
2962
3143
  readPreference?: ReadPreferenceLike;
2963
- /* Excluded from this release type: timeoutMS */
3144
+ /**
3145
+ * @experimental
3146
+ * Specifies the time an operation will run until it throws a timeout error
3147
+ */
3148
+ timeoutMS?: number;
2964
3149
  }
2965
3150
 
2966
3151
  /* Excluded from this release type: CollectionPrivate */
@@ -3003,6 +3188,9 @@ export declare interface CommandOperationOptions extends OperationOptions, Write
3003
3188
  readConcern?: ReadConcernLike;
3004
3189
  /** Collation */
3005
3190
  collation?: CollationOptions;
3191
+ /**
3192
+ * maxTimeMS is a server-side time limit in milliseconds for processing an operation.
3193
+ */
3006
3194
  maxTimeMS?: number;
3007
3195
  /**
3008
3196
  * Comment to apply to the operation.
@@ -3377,7 +3565,9 @@ export declare interface CountOptions extends CommandOperationOptions {
3377
3565
  skip?: number;
3378
3566
  /** The maximum amounts to count before aborting. */
3379
3567
  limit?: number;
3380
- /** Number of milliseconds to wait before aborting the query. */
3568
+ /**
3569
+ * Number of milliseconds to wait before aborting the query.
3570
+ */
3381
3571
  maxTimeMS?: number;
3382
3572
  /** An index name hint for the query. */
3383
3573
  hint?: string | Document;
@@ -3474,6 +3664,10 @@ export declare type CSFLEKMSTlsOptions = {
3474
3664
  [key: string]: ClientEncryptionTlsOptions | undefined;
3475
3665
  };
3476
3666
 
3667
+ /* Excluded from this release type: CSOTTimeoutContext */
3668
+
3669
+ /* Excluded from this release type: CSOTTimeoutContextOptions */
3670
+
3477
3671
  /** @public */
3478
3672
  export declare const CURSOR_FLAGS: readonly ["tailable", "oplogReplay", "noCursorTimeout", "awaitData", "exhaust", "partial"];
3479
3673
 
@@ -3488,6 +3682,48 @@ export declare interface CursorStreamOptions {
3488
3682
  transform?(this: void, doc: Document): Document;
3489
3683
  }
3490
3684
 
3685
+ /* Excluded from this release type: CursorTimeoutContext */
3686
+
3687
+ /**
3688
+ * @public
3689
+ * @experimental
3690
+ * Specifies how `timeoutMS` is applied to the cursor. Can be either `'cursorLifeTime'` or `'iteration'`
3691
+ * When set to `'iteration'`, the deadline specified by `timeoutMS` applies to each call of
3692
+ * `cursor.next()`.
3693
+ * When set to `'cursorLifetime'`, the deadline applies to the life of the entire cursor.
3694
+ *
3695
+ * Depending on the type of cursor being used, this option has different default values.
3696
+ * For non-tailable cursors, this value defaults to `'cursorLifetime'`
3697
+ * For tailable cursors, this value defaults to `'iteration'` since tailable cursors, by
3698
+ * definition can have an arbitrarily long lifetime.
3699
+ *
3700
+ * @example
3701
+ * ```ts
3702
+ * const cursor = collection.find({}, {timeoutMS: 100, timeoutMode: 'iteration'});
3703
+ * for await (const doc of cursor) {
3704
+ * // process doc
3705
+ * // This will throw a timeout error if any of the iterator's `next()` calls takes more than 100ms, but
3706
+ * // will continue to iterate successfully otherwise, regardless of the number of batches.
3707
+ * }
3708
+ * ```
3709
+ *
3710
+ * @example
3711
+ * ```ts
3712
+ * const cursor = collection.find({}, { timeoutMS: 1000, timeoutMode: 'cursorLifetime' });
3713
+ * const docs = await cursor.toArray(); // This entire line will throw a timeout error if all batches are not fetched and returned within 1000ms.
3714
+ * ```
3715
+ */
3716
+ export declare const CursorTimeoutMode: Readonly<{
3717
+ readonly ITERATION: "iteration";
3718
+ readonly LIFETIME: "cursorLifetime";
3719
+ }>;
3720
+
3721
+ /**
3722
+ * @public
3723
+ * @experimental
3724
+ */
3725
+ export declare type CursorTimeoutMode = (typeof CursorTimeoutMode)[keyof typeof CursorTimeoutMode];
3726
+
3491
3727
  /**
3492
3728
  * @public
3493
3729
  * The schema for a DataKey in the key vault collection.
@@ -3559,6 +3795,7 @@ export declare class Db {
3559
3795
  get bsonOptions(): BSONSerializeOptions;
3560
3796
  get writeConcern(): WriteConcern | undefined;
3561
3797
  get namespace(): string;
3798
+ get timeoutMS(): number | undefined;
3562
3799
  /**
3563
3800
  * Create a new collection on a server with the specified options. Use this to create capped collections.
3564
3801
  * More information about command options available at https://www.mongodb.com/docs/manual/reference/command/create/
@@ -3714,6 +3951,58 @@ export declare class Db {
3714
3951
  * - The first is to provide the schema that may be defined for all the collections within this database
3715
3952
  * - The second is to override the shape of the change stream document entirely, if it is not provided the type will default to ChangeStreamDocument of the first argument
3716
3953
  *
3954
+ * @remarks
3955
+ * When `timeoutMS` is configured for a change stream, it will have different behaviour depending
3956
+ * on whether the change stream is in iterator mode or emitter mode. In both cases, a change
3957
+ * stream will time out if it does not receive a change event within `timeoutMS` of the last change
3958
+ * event.
3959
+ *
3960
+ * Note that if a change stream is consistently timing out when watching a collection, database or
3961
+ * client that is being changed, then this may be due to the server timing out before it can finish
3962
+ * processing the existing oplog. To address this, restart the change stream with a higher
3963
+ * `timeoutMS`.
3964
+ *
3965
+ * If the change stream times out the initial aggregate operation to establish the change stream on
3966
+ * the server, then the client will close the change stream. If the getMore calls to the server
3967
+ * time out, then the change stream will be left open, but will throw a MongoOperationTimeoutError
3968
+ * when in iterator mode and emit an error event that returns a MongoOperationTimeoutError in
3969
+ * emitter mode.
3970
+ *
3971
+ * To determine whether or not the change stream is still open following a timeout, check the
3972
+ * {@link ChangeStream.closed} getter.
3973
+ *
3974
+ * @example
3975
+ * In iterator mode, if a next() call throws a timeout error, it will attempt to resume the change stream.
3976
+ * The next call can just be retried after this succeeds.
3977
+ * ```ts
3978
+ * const changeStream = collection.watch([], { timeoutMS: 100 });
3979
+ * try {
3980
+ * await changeStream.next();
3981
+ * } catch (e) {
3982
+ * if (e instanceof MongoOperationTimeoutError && !changeStream.closed) {
3983
+ * await changeStream.next();
3984
+ * }
3985
+ * throw e;
3986
+ * }
3987
+ * ```
3988
+ *
3989
+ * @example
3990
+ * In emitter mode, if the change stream goes `timeoutMS` without emitting a change event, it will
3991
+ * emit an error event that returns a MongoOperationTimeoutError, but will not close the change
3992
+ * stream unless the resume attempt fails. There is no need to re-establish change listeners as
3993
+ * this will automatically continue emitting change events once the resume attempt completes.
3994
+ *
3995
+ * ```ts
3996
+ * const changeStream = collection.watch([], { timeoutMS: 100 });
3997
+ * changeStream.on('change', console.log);
3998
+ * changeStream.on('error', e => {
3999
+ * if (e instanceof MongoOperationTimeoutError && !changeStream.closed) {
4000
+ * // do nothing
4001
+ * } else {
4002
+ * changeStream.close();
4003
+ * }
4004
+ * });
4005
+ * ```
3717
4006
  * @param pipeline - An array of {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation-pipeline/|aggregation pipeline stages} through which to pass change stream documents. This allows for filtering (using $match) and manipulating the change stream documents.
3718
4007
  * @param options - Optional settings for the command
3719
4008
  * @typeParam TSchema - Type of the data being detected by the change stream
@@ -3748,7 +4037,11 @@ export declare interface DbOptions extends BSONSerializeOptions, WriteConcernOpt
3748
4037
  readConcern?: ReadConcern;
3749
4038
  /** Should retry failed writes */
3750
4039
  retryWrites?: boolean;
3751
- /* Excluded from this release type: timeoutMS */
4040
+ /**
4041
+ * @experimental
4042
+ * Specifies the time an operation will run until it throws a timeout error
4043
+ */
4044
+ timeoutMS?: number;
3752
4045
  }
3753
4046
 
3754
4047
  /* Excluded from this release type: DbPrivate */
@@ -3851,6 +4144,8 @@ export declare interface EndSessionOptions {
3851
4144
  /* Excluded from this release type: error */
3852
4145
  force?: boolean;
3853
4146
  forceClear?: boolean;
4147
+ /** Specifies the time an operation will run until it throws a timeout error */
4148
+ timeoutMS?: number;
3854
4149
  }
3855
4150
 
3856
4151
  /** TypeScript Omit (Exclude to be specific) does not work for objects with an "any" indexed type, and breaks discriminated unions @public */
@@ -3888,6 +4183,38 @@ export declare type EventsDescription = Record<string, GenericListener>;
3888
4183
 
3889
4184
  /* Excluded from this release type: Explain */
3890
4185
 
4186
+ /**
4187
+ * @public
4188
+ *
4189
+ * A base class for any cursors that have `explain()` methods.
4190
+ */
4191
+ export declare abstract class ExplainableCursor<TSchema> extends AbstractCursor<TSchema> {
4192
+ /** Execute the explain for the cursor */
4193
+ abstract explain(): Promise<Document>;
4194
+ abstract explain(verbosity: ExplainVerbosityLike | ExplainCommandOptions): Promise<Document>;
4195
+ abstract explain(options: {
4196
+ timeoutMS?: number;
4197
+ }): Promise<Document>;
4198
+ abstract explain(verbosity: ExplainVerbosityLike | ExplainCommandOptions, options: {
4199
+ timeoutMS?: number;
4200
+ }): Promise<Document>;
4201
+ abstract explain(verbosity?: ExplainVerbosityLike | ExplainCommandOptions | {
4202
+ timeoutMS?: number;
4203
+ }, options?: {
4204
+ timeoutMS?: number;
4205
+ }): Promise<Document>;
4206
+ protected resolveExplainTimeoutOptions(verbosity?: ExplainVerbosityLike | ExplainCommandOptions | {
4207
+ timeoutMS?: number;
4208
+ }, options?: {
4209
+ timeoutMS?: number;
4210
+ }): {
4211
+ timeout?: {
4212
+ timeoutMS?: number;
4213
+ };
4214
+ explain?: ExplainVerbosityLike | ExplainCommandOptions;
4215
+ };
4216
+ }
4217
+
3891
4218
  /** @public */
3892
4219
  export declare interface ExplainCommandOptions {
3893
4220
  /** The explain verbosity for the command. */
@@ -3998,7 +4325,7 @@ export declare interface FilterOperators<TValue> extends NonObjectIdLikeDocument
3998
4325
  }
3999
4326
 
4000
4327
  /** @public */
4001
- export declare class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
4328
+ export declare class FindCursor<TSchema = any> extends ExplainableCursor<TSchema> {
4002
4329
  /* Excluded from this release type: cursorFilter */
4003
4330
  /* Excluded from this release type: numReturned */
4004
4331
  /* Excluded from this release type: findOptions */
@@ -4013,7 +4340,14 @@ export declare class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
4013
4340
  */
4014
4341
  count(options?: CountOptions): Promise<number>;
4015
4342
  /** Execute the explain for the cursor */
4016
- explain(verbosity?: ExplainVerbosityLike | ExplainCommandOptions): Promise<Document>;
4343
+ explain(): Promise<Document>;
4344
+ explain(verbosity: ExplainVerbosityLike | ExplainCommandOptions): Promise<Document>;
4345
+ explain(options: {
4346
+ timeoutMS?: number;
4347
+ }): Promise<Document>;
4348
+ explain(verbosity: ExplainVerbosityLike | ExplainCommandOptions, options: {
4349
+ timeoutMS?: number;
4350
+ }): Promise<Document>;
4017
4351
  /** Set the cursor query */
4018
4352
  filter(filter: Document): this;
4019
4353
  /**
@@ -4243,7 +4577,7 @@ export declare class FindOperators {
4243
4577
  * @public
4244
4578
  * @typeParam TSchema - Unused schema definition, deprecated usage, only specify `FindOptions` with no generic
4245
4579
  */
4246
- export declare interface FindOptions<TSchema extends Document = Document> extends Omit<CommandOperationOptions, 'writeConcern' | 'explain'> {
4580
+ export declare interface FindOptions<TSchema extends Document = Document> extends Omit<CommandOperationOptions, 'writeConcern' | 'explain'>, AbstractCursorOptions {
4247
4581
  /** Sets the limit of documents returned in the query. */
4248
4582
  limit?: number;
4249
4583
  /** Set to sort the documents coming back from the query. Array of indexes, `[['a', 1]]` etc. */
@@ -4296,6 +4630,7 @@ export declare interface FindOptions<TSchema extends Document = Document> extend
4296
4630
  * @deprecated This API is deprecated in favor of `collection.find().explain()`.
4297
4631
  */
4298
4632
  explain?: ExplainOptions['explain'];
4633
+ /* Excluded from this release type: timeoutMode */
4299
4634
  }
4300
4635
 
4301
4636
  /** @public */
@@ -4395,7 +4730,9 @@ export declare class GridFSBucket extends TypedEventEmitter<GridFSBucketEvents>
4395
4730
  *
4396
4731
  * @param id - The id of the file doc
4397
4732
  */
4398
- delete(id: ObjectId): Promise<void>;
4733
+ delete(id: ObjectId, options?: {
4734
+ timeoutMS: number;
4735
+ }): Promise<void>;
4399
4736
  /** Convenience wrapper around find on the files collection */
4400
4737
  find(filter?: Filter<GridFSFile>, options?: FindOptions): FindCursor<GridFSFile>;
4401
4738
  /**
@@ -4412,9 +4749,13 @@ export declare class GridFSBucket extends TypedEventEmitter<GridFSBucketEvents>
4412
4749
  * @param id - the id of the file to rename
4413
4750
  * @param filename - new name for the file
4414
4751
  */
4415
- rename(id: ObjectId, filename: string): Promise<void>;
4752
+ rename(id: ObjectId, filename: string, options?: {
4753
+ timeoutMS: number;
4754
+ }): Promise<void>;
4416
4755
  /** Removes this bucket's files collection, followed by its chunks collection. */
4417
- drop(): Promise<void>;
4756
+ drop(options?: {
4757
+ timeoutMS: number;
4758
+ }): Promise<void>;
4418
4759
  }
4419
4760
 
4420
4761
  /** @public */
@@ -4430,7 +4771,12 @@ export declare interface GridFSBucketOptions extends WriteConcernOptions {
4430
4771
  chunkSizeBytes?: number;
4431
4772
  /** Read preference to be passed to read operations */
4432
4773
  readPreference?: ReadPreference;
4433
- /* Excluded from this release type: timeoutMS */
4774
+ /**
4775
+ * @experimental
4776
+ * Specifies the lifetime duration of a gridFS stream. If any async operations are in progress
4777
+ * when this timeout expires, the stream will throw a timeout error.
4778
+ */
4779
+ timeoutMS?: number;
4434
4780
  }
4435
4781
 
4436
4782
  /* Excluded from this release type: GridFSBucketPrivate */
@@ -4487,7 +4833,11 @@ export declare interface GridFSBucketReadStreamOptions {
4487
4833
  * to be returned by the stream. `end` is non-inclusive
4488
4834
  */
4489
4835
  end?: number;
4490
- /* Excluded from this release type: timeoutMS */
4836
+ /**
4837
+ * @experimental
4838
+ * Specifies the time an operation will run until it throws a timeout error
4839
+ */
4840
+ timeoutMS?: number;
4491
4841
  }
4492
4842
 
4493
4843
  /** @public */
@@ -4558,6 +4908,7 @@ export declare class GridFSBucketWriteStream extends Writable {
4558
4908
  * ```
4559
4909
  */
4560
4910
  gridFSFile: GridFSFile | null;
4911
+ /* Excluded from this release type: timeoutContext */
4561
4912
  /* Excluded from this release type: __constructor */
4562
4913
  /* Excluded from this release type: _construct */
4563
4914
  /* Excluded from this release type: _write */
@@ -4587,7 +4938,11 @@ export declare interface GridFSBucketWriteStreamOptions extends WriteConcernOpti
4587
4938
  * @deprecated Will be removed in the next major version. Add an aliases field to the metadata document instead.
4588
4939
  */
4589
4940
  aliases?: string[];
4590
- /* Excluded from this release type: timeoutMS */
4941
+ /**
4942
+ * @experimental
4943
+ * Specifies the time an operation will run until it throws a timeout error
4944
+ */
4945
+ timeoutMS?: number;
4591
4946
  }
4592
4947
 
4593
4948
  /** @public */
@@ -4944,6 +5299,10 @@ export declare interface KMSProviders {
4944
5299
 
4945
5300
  /* Excluded from this release type: kWaitQueue_2 */
4946
5301
 
5302
+ /* Excluded from this release type: LegacyTimeoutContext */
5303
+
5304
+ /* Excluded from this release type: LegacyTimeoutContextOptions */
5305
+
4947
5306
  /** @public */
4948
5307
  export declare const LEGAL_TCP_SOCKET_OPTIONS: readonly ["autoSelectFamily", "autoSelectFamilyAttemptTimeout", "family", "hints", "localAddress", "localPort", "lookup"];
4949
5308
 
@@ -4970,6 +5329,8 @@ export declare interface ListCollectionsOptions extends Omit<CommandOperationOpt
4970
5329
  authorizedCollections?: boolean;
4971
5330
  /** The batchSize for the returned command cursor or if pre 2.8 the systems batch collection */
4972
5331
  batchSize?: number;
5332
+ /* Excluded from this release type: timeoutMode */
5333
+ /* Excluded from this release type: timeoutContext */
4973
5334
  }
4974
5335
 
4975
5336
  /** @public */
@@ -5004,7 +5365,9 @@ export declare class ListIndexesCursor extends AbstractCursor {
5004
5365
  }
5005
5366
 
5006
5367
  /** @public */
5007
- export declare type ListIndexesOptions = AbstractCursorOptions;
5368
+ export declare type ListIndexesOptions = AbstractCursorOptions & {
5369
+ /* Excluded from this release type: omitMaxTimeMS */
5370
+ };
5008
5371
 
5009
5372
  /** @public */
5010
5373
  export declare class ListSearchIndexesCursor extends AggregationCursor<{
@@ -5269,6 +5632,7 @@ export declare class MongoClient extends TypedEventEmitter<MongoClientEvents> im
5269
5632
  get writeConcern(): WriteConcern | undefined;
5270
5633
  get readPreference(): ReadPreference;
5271
5634
  get bsonOptions(): BSONSerializeOptions;
5635
+ get timeoutMS(): number | undefined;
5272
5636
  /**
5273
5637
  * Executes a client bulk write operation, available on server 8.0+.
5274
5638
  * @param models - The client bulk write models.
@@ -5279,6 +5643,13 @@ export declare class MongoClient extends TypedEventEmitter<MongoClientEvents> im
5279
5643
  /**
5280
5644
  * Connect to MongoDB using a url
5281
5645
  *
5646
+ * @remarks
5647
+ * Calling `connect` is optional since the first operation you perform will call `connect` if it's needed.
5648
+ * `timeoutMS` will bound the time any operation can take before throwing a timeout error.
5649
+ * However, when the operation being run is automatically connecting your `MongoClient` the `timeoutMS` will not apply to the time taken to connect the MongoClient.
5650
+ * This means the time to setup the `MongoClient` does not count against `timeoutMS`.
5651
+ * If you are using `timeoutMS` we recommend connecting your client explicitly in advance of any operation to avoid this inconsistent execution time.
5652
+ *
5282
5653
  * @see docs.mongodb.org/manual/reference/connection-string/
5283
5654
  */
5284
5655
  connect(): Promise<this>;
@@ -5308,6 +5679,13 @@ export declare class MongoClient extends TypedEventEmitter<MongoClientEvents> im
5308
5679
  * Connect to MongoDB using a url
5309
5680
  *
5310
5681
  * @remarks
5682
+ * Calling `connect` is optional since the first operation you perform will call `connect` if it's needed.
5683
+ * `timeoutMS` will bound the time any operation can take before throwing a timeout error.
5684
+ * However, when the operation being run is automatically connecting your `MongoClient` the `timeoutMS` will not apply to the time taken to connect the MongoClient.
5685
+ * This means the time to setup the `MongoClient` does not count against `timeoutMS`.
5686
+ * If you are using `timeoutMS` we recommend connecting your client explicitly in advance of any operation to avoid this inconsistent execution time.
5687
+ *
5688
+ * @remarks
5311
5689
  * The programmatically provided options take precedence over the URI options.
5312
5690
  *
5313
5691
  * @see https://www.mongodb.com/docs/manual/reference/connection-string/
@@ -5341,6 +5719,58 @@ export declare class MongoClient extends TypedEventEmitter<MongoClientEvents> im
5341
5719
  * - The first is to provide the schema that may be defined for all the data within the current cluster
5342
5720
  * - The second is to override the shape of the change stream document entirely, if it is not provided the type will default to ChangeStreamDocument of the first argument
5343
5721
  *
5722
+ * @remarks
5723
+ * When `timeoutMS` is configured for a change stream, it will have different behaviour depending
5724
+ * on whether the change stream is in iterator mode or emitter mode. In both cases, a change
5725
+ * stream will time out if it does not receive a change event within `timeoutMS` of the last change
5726
+ * event.
5727
+ *
5728
+ * Note that if a change stream is consistently timing out when watching a collection, database or
5729
+ * client that is being changed, then this may be due to the server timing out before it can finish
5730
+ * processing the existing oplog. To address this, restart the change stream with a higher
5731
+ * `timeoutMS`.
5732
+ *
5733
+ * If the change stream times out the initial aggregate operation to establish the change stream on
5734
+ * the server, then the client will close the change stream. If the getMore calls to the server
5735
+ * time out, then the change stream will be left open, but will throw a MongoOperationTimeoutError
5736
+ * when in iterator mode and emit an error event that returns a MongoOperationTimeoutError in
5737
+ * emitter mode.
5738
+ *
5739
+ * To determine whether or not the change stream is still open following a timeout, check the
5740
+ * {@link ChangeStream.closed} getter.
5741
+ *
5742
+ * @example
5743
+ * In iterator mode, if a next() call throws a timeout error, it will attempt to resume the change stream.
5744
+ * The next call can just be retried after this succeeds.
5745
+ * ```ts
5746
+ * const changeStream = collection.watch([], { timeoutMS: 100 });
5747
+ * try {
5748
+ * await changeStream.next();
5749
+ * } catch (e) {
5750
+ * if (e instanceof MongoOperationTimeoutError && !changeStream.closed) {
5751
+ * await changeStream.next();
5752
+ * }
5753
+ * throw e;
5754
+ * }
5755
+ * ```
5756
+ *
5757
+ * @example
5758
+ * In emitter mode, if the change stream goes `timeoutMS` without emitting a change event, it will
5759
+ * emit an error event that returns a MongoOperationTimeoutError, but will not close the change
5760
+ * stream unless the resume attempt fails. There is no need to re-establish change listeners as
5761
+ * this will automatically continue emitting change events once the resume attempt completes.
5762
+ *
5763
+ * ```ts
5764
+ * const changeStream = collection.watch([], { timeoutMS: 100 });
5765
+ * changeStream.on('change', console.log);
5766
+ * changeStream.on('error', e => {
5767
+ * if (e instanceof MongoOperationTimeoutError && !changeStream.closed) {
5768
+ * // do nothing
5769
+ * } else {
5770
+ * changeStream.close();
5771
+ * }
5772
+ * });
5773
+ * ```
5344
5774
  * @param pipeline - An array of {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation-pipeline/|aggregation pipeline stages} through which to pass change stream documents. This allows for filtering (using $match) and manipulating the change stream documents.
5345
5775
  * @param options - Optional settings for the command
5346
5776
  * @typeParam TSchema - Type of the data being detected by the change stream
@@ -5438,7 +5868,11 @@ export declare type MongoClientEvents = Pick<TopologyEvents, (typeof MONGO_CLIEN
5438
5868
  export declare interface MongoClientOptions extends BSONSerializeOptions, SupportedNodeConnectionOptions {
5439
5869
  /** Specifies the name of the replica set, if the mongod is a member of a replica set. */
5440
5870
  replicaSet?: string;
5441
- /* Excluded from this release type: timeoutMS */
5871
+ /**
5872
+ * @experimental
5873
+ * Specifies the time an operation will run until it throws a timeout error
5874
+ */
5875
+ timeoutMS?: number;
5442
5876
  /** Enables or disables TLS/SSL for the connection. */
5443
5877
  tls?: boolean;
5444
5878
  /** A boolean to enable or disables TLS/SSL for the connection. (The ssl option is equivalent to the tls option.) */
@@ -5558,7 +5992,7 @@ export declare interface MongoClientOptions extends BSONSerializeOptions, Suppor
5558
5992
  *
5559
5993
  * @remarks
5560
5994
  * Automatic encryption is an enterprise only feature that only applies to operations on a collection. Automatic encryption is not supported for operations on a database or view, and operations that are not bypassed will result in error
5561
- * (see [libmongocrypt: Auto Encryption Allow-List](https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/client-side-encryption.rst#libmongocrypt-auto-encryption-allow-list)). To bypass automatic encryption for all operations, set bypassAutoEncryption=true in AutoEncryptionOpts.
5995
+ * (see [libmongocrypt: Auto Encryption Allow-List](https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/client-side-encryption.md#libmongocrypt-auto-encryption-allow-list)). To bypass automatic encryption for all operations, set bypassAutoEncryption=true in AutoEncryptionOpts.
5562
5996
  *
5563
5997
  * Automatic encryption requires the authenticated user to have the [listCollections privilege action](https://www.mongodb.com/docs/manual/reference/command/listCollections/#dbcmd.listCollections).
5564
5998
  *
@@ -6262,6 +6696,29 @@ export declare class MongoOIDCError extends MongoRuntimeError {
6262
6696
  get name(): string;
6263
6697
  }
6264
6698
 
6699
+ /**
6700
+ * @public
6701
+ * @category Error
6702
+ *
6703
+ * The `MongoOperationTimeoutError` class represents an error that occurs when an operation could not be completed within the specified `timeoutMS`.
6704
+ * It is generated by the driver in support of the "client side operation timeout" feature so inherits from `MongoDriverError`.
6705
+ * When `timeoutMS` is enabled `MongoServerError`s relating to `MaxTimeExpired` errors will be converted to `MongoOperationTimeoutError`
6706
+ *
6707
+ * @example
6708
+ * ```ts
6709
+ * try {
6710
+ * await blogs.insertOne(blogPost, { timeoutMS: 60_000 })
6711
+ * } catch (error) {
6712
+ * if (error instanceof MongoOperationTimeoutError) {
6713
+ * console.log(`Oh no! writer's block!`, error);
6714
+ * }
6715
+ * }
6716
+ * ```
6717
+ */
6718
+ export declare class MongoOperationTimeoutError extends MongoDriverError {
6719
+ get name(): string;
6720
+ }
6721
+
6265
6722
  /**
6266
6723
  * Parsed Mongo Client Options.
6267
6724
  *
@@ -6350,7 +6807,7 @@ export declare interface MongoOptions extends Required<Pick<MongoClientOptions,
6350
6807
  /* Excluded from this release type: __index */
6351
6808
  /* Excluded from this release type: mongoLoggerOptions */
6352
6809
  /* Excluded from this release type: mongodbLogPath */
6353
- /* Excluded from this release type: timeoutMS */
6810
+ timeoutMS?: number;
6354
6811
  }
6355
6812
 
6356
6813
  /**
@@ -6376,7 +6833,7 @@ export declare class MongoParseError extends MongoDriverError {
6376
6833
 
6377
6834
  /**
6378
6835
  * An error generated when the driver encounters unexpected input
6379
- * or reaches an unexpected/invalid internal state
6836
+ * or reaches an unexpected/invalid internal state.
6380
6837
  *
6381
6838
  * @privateRemarks
6382
6839
  * Should **never** be directly instantiated.
@@ -6764,7 +7221,12 @@ export declare interface OperationOptions extends BSONSerializeOptions {
6764
7221
  readPreference?: ReadPreferenceLike;
6765
7222
  /* Excluded from this release type: bypassPinningCheck */
6766
7223
  omitReadPreference?: boolean;
6767
- /* Excluded from this release type: timeoutMS */
7224
+ /* Excluded from this release type: omitMaxTimeMS */
7225
+ /**
7226
+ * @experimental
7227
+ * Specifies the time an operation will run until it throws a timeout error
7228
+ */
7229
+ timeoutMS?: number;
6768
7230
  }
6769
7231
 
6770
7232
  /* Excluded from this release type: OperationParent */
@@ -7153,7 +7615,7 @@ export declare class RunCommandCursor extends AbstractCursor {
7153
7615
  setMaxTimeMS(maxTimeMS: number): this;
7154
7616
  /**
7155
7617
  * Controls the `getMore.batchSize` field
7156
- * @param maxTimeMS - the number documents to return in the `nextBatch`
7618
+ * @param batchSize - the number documents to return in the `nextBatch`
7157
7619
  */
7158
7620
  setBatchSize(batchSize: number): this;
7159
7621
  /** Unsupported for RunCommandCursor */
@@ -7162,7 +7624,9 @@ export declare class RunCommandCursor extends AbstractCursor {
7162
7624
  withReadConcern(_: ReadConcernLike): never;
7163
7625
  /** Unsupported for RunCommandCursor: various cursor flags must be configured directly on command document */
7164
7626
  addCursorFlag(_: string, __: boolean): never;
7165
- /** Unsupported for RunCommandCursor: maxTimeMS must be configured directly on command document */
7627
+ /**
7628
+ * Unsupported for RunCommandCursor: maxTimeMS must be configured directly on command document
7629
+ */
7166
7630
  maxTimeMS(_: number): never;
7167
7631
  /** Unsupported for RunCommandCursor: batchSize must be configured directly on command document */
7168
7632
  batchSize(_: number): never;
@@ -7178,12 +7642,57 @@ export declare type RunCommandOptions = {
7178
7642
  session?: ClientSession;
7179
7643
  /** The read preference */
7180
7644
  readPreference?: ReadPreferenceLike;
7645
+ /**
7646
+ * @experimental
7647
+ * Specifies the time an operation will run until it throws a timeout error
7648
+ */
7649
+ timeoutMS?: number;
7650
+ /* Excluded from this release type: omitMaxTimeMS */
7181
7651
  } & BSONSerializeOptions;
7182
7652
 
7183
7653
  /** @public */
7184
7654
  export declare type RunCursorCommandOptions = {
7185
7655
  readPreference?: ReadPreferenceLike;
7186
7656
  session?: ClientSession;
7657
+ /**
7658
+ * @experimental
7659
+ * Specifies the time an operation will run until it throws a timeout error. Note that if
7660
+ * `maxTimeMS` is provided in the command in addition to setting `timeoutMS` in the options, then
7661
+ * the original value of `maxTimeMS` will be overwritten.
7662
+ */
7663
+ timeoutMS?: number;
7664
+ /**
7665
+ * @public
7666
+ * @experimental
7667
+ * Specifies how `timeoutMS` is applied to the cursor. Can be either `'cursorLifeTime'` or `'iteration'`
7668
+ * When set to `'iteration'`, the deadline specified by `timeoutMS` applies to each call of
7669
+ * `cursor.next()`.
7670
+ * When set to `'cursorLifetime'`, the deadline applies to the life of the entire cursor.
7671
+ *
7672
+ * Depending on the type of cursor being used, this option has different default values.
7673
+ * For non-tailable cursors, this value defaults to `'cursorLifetime'`
7674
+ * For tailable cursors, this value defaults to `'iteration'` since tailable cursors, by
7675
+ * definition can have an arbitrarily long lifetime.
7676
+ *
7677
+ * @example
7678
+ * ```ts
7679
+ * const cursor = collection.find({}, {timeoutMS: 100, timeoutMode: 'iteration'});
7680
+ * for await (const doc of cursor) {
7681
+ * // process doc
7682
+ * // This will throw a timeout error if any of the iterator's `next()` calls takes more than 100ms, but
7683
+ * // will continue to iterate successfully otherwise, regardless of the number of batches.
7684
+ * }
7685
+ * ```
7686
+ *
7687
+ * @example
7688
+ * ```ts
7689
+ * const cursor = collection.find({}, { timeoutMS: 1000, timeoutMode: 'cursorLifetime' });
7690
+ * const docs = await cursor.toArray(); // This entire line will throw a timeout error if all batches are not fetched and returned within 1000ms.
7691
+ * ```
7692
+ */
7693
+ timeoutMode?: CursorTimeoutMode;
7694
+ tailable?: boolean;
7695
+ awaitData?: boolean;
7187
7696
  } & BSONSerializeOptions;
7188
7697
 
7189
7698
  /** @public */
@@ -7213,7 +7722,7 @@ export declare interface SelectServerOptions {
7213
7722
  session?: ClientSession;
7214
7723
  operationName: string;
7215
7724
  previousServer?: ServerDescription;
7216
- /* Excluded from this release type: timeout */
7725
+ /* Excluded from this release type: timeoutContext */
7217
7726
  }
7218
7727
 
7219
7728
  export { serialize }
@@ -7283,6 +7792,8 @@ export declare class ServerClosedEvent {
7283
7792
  /* Excluded from this release type: __constructor */
7284
7793
  }
7285
7794
 
7795
+ /* Excluded from this release type: ServerCommandOptions */
7796
+
7286
7797
  /**
7287
7798
  * The client's view of a single server, based on the most recent hello outcome.
7288
7799
  *
@@ -7317,6 +7828,8 @@ export declare class ServerDescription {
7317
7828
  maxWriteBatchSize: number | null;
7318
7829
  /** The max bson object size. */
7319
7830
  maxBsonObjectSize: number | null;
7831
+ /** Indicates server is a mongocryptd instance. */
7832
+ iscryptd: boolean;
7320
7833
  $clusterTime?: ClusterTime;
7321
7834
  /* Excluded from this release type: __constructor */
7322
7835
  get hostAddress(): HostAddress;
@@ -7330,8 +7843,8 @@ export declare class ServerDescription {
7330
7843
  get host(): string;
7331
7844
  get port(): number;
7332
7845
  /**
7333
- * Determines if another `ServerDescription` is equal to this one per the rules defined
7334
- * in the {@link https://github.com/mongodb/specifications/blob/master/source/server-discovery-and-monitoring/server-discovery-and-monitoring.rst#serverdescription|SDAM spec}
7846
+ * Determines if another `ServerDescription` is equal to this one per the rules defined in the SDAM specification.
7847
+ * @see https://github.com/mongodb/specifications/blob/master/source/server-discovery-and-monitoring/server-discovery-and-monitoring.md
7335
7848
  */
7336
7849
  equals(other?: ServerDescription | null): boolean;
7337
7850
  }
@@ -7478,7 +7991,6 @@ export declare class ServerSession {
7478
7991
  * @param sessionTimeoutMinutes - The server's "logicalSessionTimeoutMinutes"
7479
7992
  */
7480
7993
  hasTimedOut(sessionTimeoutMinutes: number): boolean;
7481
- /* Excluded from this release type: clone */
7482
7994
  }
7483
7995
 
7484
7996
  /** @public */
@@ -7652,7 +8164,9 @@ export declare type TagSet = {
7652
8164
 
7653
8165
  /* Excluded from this release type: Timeout */
7654
8166
 
7655
- /* Excluded from this release type: TimerQueue */
8167
+ /* Excluded from this release type: TimeoutContext */
8168
+
8169
+ /* Excluded from this release type: TimeoutContextOptions */
7656
8170
 
7657
8171
  /** @public
7658
8172
  * Configuration options for timeseries collections
@@ -7836,7 +8350,7 @@ export declare class Transaction {
7836
8350
  * Configuration options for a transaction.
7837
8351
  * @public
7838
8352
  */
7839
- export declare interface TransactionOptions extends CommandOperationOptions {
8353
+ export declare interface TransactionOptions extends Omit<CommandOperationOptions, 'timeoutMS'> {
7840
8354
  /** A default read concern for commands in this transaction */
7841
8355
  readConcern?: ReadConcernLike;
7842
8356
  /** A default writeConcern for commands in this transaction */
@@ -8115,7 +8629,9 @@ export declare class WriteConcern {
8115
8629
  readonly w?: W;
8116
8630
  /** Request acknowledgment that the write operation has been written to the on-disk journal */
8117
8631
  readonly journal?: boolean;
8118
- /** Specify a time limit to prevent write operations from blocking indefinitely */
8632
+ /**
8633
+ * Specify a time limit to prevent write operations from blocking indefinitely.
8634
+ */
8119
8635
  readonly wtimeoutMS?: number;
8120
8636
  /**
8121
8637
  * Specify a time limit to prevent write operations from blocking indefinitely.
@@ -8200,7 +8716,9 @@ export declare interface WriteConcernOptions {
8200
8716
  export declare interface WriteConcernSettings {
8201
8717
  /** The write concern */
8202
8718
  w?: W;
8203
- /** The write concern timeout */
8719
+ /**
8720
+ * The write concern timeout.
8721
+ */
8204
8722
  wtimeoutMS?: number;
8205
8723
  /** The journal write concern */
8206
8724
  journal?: boolean;
@@ -8211,7 +8729,6 @@ export declare interface WriteConcernSettings {
8211
8729
  j?: boolean;
8212
8730
  /**
8213
8731
  * The write concern timeout.
8214
- * @deprecated Will be removed in the next major version. Please use the wtimeoutMS option.
8215
8732
  */
8216
8733
  wtimeout?: number;
8217
8734
  /**