mongodb 4.0.0 → 4.1.2

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 (246) hide show
  1. package/README.md +62 -30
  2. package/lib/bson.js +1 -0
  3. package/lib/bson.js.map +1 -1
  4. package/lib/bulk/common.js +53 -30
  5. package/lib/bulk/common.js.map +1 -1
  6. package/lib/bulk/ordered.js +3 -2
  7. package/lib/bulk/ordered.js.map +1 -1
  8. package/lib/bulk/unordered.js +3 -2
  9. package/lib/bulk/unordered.js.map +1 -1
  10. package/lib/change_stream.js +23 -13
  11. package/lib/change_stream.js.map +1 -1
  12. package/lib/cmap/auth/auth_provider.js +2 -1
  13. package/lib/cmap/auth/auth_provider.js.map +1 -1
  14. package/lib/cmap/auth/gssapi.js +5 -4
  15. package/lib/cmap/auth/gssapi.js.map +1 -1
  16. package/lib/cmap/auth/mongo_credentials.js +9 -5
  17. package/lib/cmap/auth/mongo_credentials.js.map +1 -1
  18. package/lib/cmap/auth/mongocr.js +2 -2
  19. package/lib/cmap/auth/mongocr.js.map +1 -1
  20. package/lib/cmap/auth/mongodb_aws.js +32 -32
  21. package/lib/cmap/auth/mongodb_aws.js.map +1 -1
  22. package/lib/cmap/auth/plain.js +1 -1
  23. package/lib/cmap/auth/plain.js.map +1 -1
  24. package/lib/cmap/auth/scram.js +15 -12
  25. package/lib/cmap/auth/scram.js.map +1 -1
  26. package/lib/cmap/auth/x509.js +2 -2
  27. package/lib/cmap/auth/x509.js.map +1 -1
  28. package/lib/cmap/command_monitoring_events.js +26 -10
  29. package/lib/cmap/command_monitoring_events.js.map +1 -1
  30. package/lib/cmap/commands.js +9 -5
  31. package/lib/cmap/commands.js.map +1 -1
  32. package/lib/cmap/connect.js +23 -9
  33. package/lib/cmap/connect.js.map +1 -1
  34. package/lib/cmap/connection.js +43 -46
  35. package/lib/cmap/connection.js.map +1 -1
  36. package/lib/cmap/connection_pool.js +113 -15
  37. package/lib/cmap/connection_pool.js.map +1 -1
  38. package/lib/cmap/connection_pool_events.js +3 -1
  39. package/lib/cmap/connection_pool_events.js.map +1 -1
  40. package/lib/cmap/errors.js +3 -3
  41. package/lib/cmap/errors.js.map +1 -1
  42. package/lib/cmap/message_stream.js +1 -1
  43. package/lib/cmap/message_stream.js.map +1 -1
  44. package/lib/cmap/metrics.js +62 -0
  45. package/lib/cmap/metrics.js.map +1 -0
  46. package/lib/cmap/stream_description.js +3 -1
  47. package/lib/cmap/stream_description.js.map +1 -1
  48. package/lib/cmap/wire_protocol/compression.js +22 -9
  49. package/lib/cmap/wire_protocol/compression.js.map +1 -1
  50. package/lib/cmap/wire_protocol/shared.js +1 -1
  51. package/lib/cmap/wire_protocol/shared.js.map +1 -1
  52. package/lib/collection.js +23 -18
  53. package/lib/collection.js.map +1 -1
  54. package/lib/connection_string.js +76 -30
  55. package/lib/connection_string.js.map +1 -1
  56. package/lib/cursor/abstract_cursor.js +75 -68
  57. package/lib/cursor/abstract_cursor.js.map +1 -1
  58. package/lib/cursor/aggregation_cursor.js +47 -9
  59. package/lib/cursor/aggregation_cursor.js.map +1 -1
  60. package/lib/cursor/find_cursor.js +53 -13
  61. package/lib/cursor/find_cursor.js.map +1 -1
  62. package/lib/db.js +21 -14
  63. package/lib/db.js.map +1 -1
  64. package/lib/deps.js +16 -5
  65. package/lib/deps.js.map +1 -1
  66. package/lib/encrypter.js +5 -8
  67. package/lib/encrypter.js.map +1 -1
  68. package/lib/error.js +230 -34
  69. package/lib/error.js.map +1 -1
  70. package/lib/explain.js +2 -2
  71. package/lib/explain.js.map +1 -1
  72. package/lib/gridfs/download.js +22 -47
  73. package/lib/gridfs/download.js.map +1 -1
  74. package/lib/gridfs/index.js +4 -3
  75. package/lib/gridfs/index.js.map +1 -1
  76. package/lib/gridfs/upload.js +13 -21
  77. package/lib/gridfs/upload.js.map +1 -1
  78. package/lib/index.js +27 -2
  79. package/lib/index.js.map +1 -1
  80. package/lib/logger.js +3 -2
  81. package/lib/logger.js.map +1 -1
  82. package/lib/mongo_client.js +5 -8
  83. package/lib/mongo_client.js.map +1 -1
  84. package/lib/mongo_types.js.map +1 -1
  85. package/lib/operations/add_user.js +2 -3
  86. package/lib/operations/add_user.js.map +1 -1
  87. package/lib/operations/aggregate.js +12 -9
  88. package/lib/operations/aggregate.js.map +1 -1
  89. package/lib/operations/command.js +5 -7
  90. package/lib/operations/command.js.map +1 -1
  91. package/lib/operations/common_functions.js +1 -1
  92. package/lib/operations/common_functions.js.map +1 -1
  93. package/lib/operations/connect.js +3 -2
  94. package/lib/operations/connect.js.map +1 -1
  95. package/lib/operations/count.js +1 -1
  96. package/lib/operations/count.js.map +1 -1
  97. package/lib/operations/count_documents.js +1 -1
  98. package/lib/operations/count_documents.js.map +1 -1
  99. package/lib/operations/delete.js +5 -5
  100. package/lib/operations/delete.js.map +1 -1
  101. package/lib/operations/distinct.js +2 -2
  102. package/lib/operations/distinct.js.map +1 -1
  103. package/lib/operations/estimated_document_count.js +5 -1
  104. package/lib/operations/estimated_document_count.js.map +1 -1
  105. package/lib/operations/eval.js.map +1 -1
  106. package/lib/operations/execute_operation.js +31 -17
  107. package/lib/operations/execute_operation.js.map +1 -1
  108. package/lib/operations/find.js +13 -9
  109. package/lib/operations/find.js.map +1 -1
  110. package/lib/operations/find_and_modify.js +9 -9
  111. package/lib/operations/find_and_modify.js.map +1 -1
  112. package/lib/operations/indexes.js +8 -3
  113. package/lib/operations/indexes.js.map +1 -1
  114. package/lib/operations/insert.js +5 -3
  115. package/lib/operations/insert.js.map +1 -1
  116. package/lib/operations/is_capped.js +2 -1
  117. package/lib/operations/is_capped.js.map +1 -1
  118. package/lib/operations/list_collections.js +6 -3
  119. package/lib/operations/list_collections.js.map +1 -1
  120. package/lib/operations/map_reduce.js +1 -1
  121. package/lib/operations/map_reduce.js.map +1 -1
  122. package/lib/operations/operation.js +3 -1
  123. package/lib/operations/operation.js.map +1 -1
  124. package/lib/operations/options_operation.js +2 -1
  125. package/lib/operations/options_operation.js.map +1 -1
  126. package/lib/operations/profiling_level.js +4 -2
  127. package/lib/operations/profiling_level.js.map +1 -1
  128. package/lib/operations/set_profiling_level.js +4 -2
  129. package/lib/operations/set_profiling_level.js.map +1 -1
  130. package/lib/operations/update.js +12 -12
  131. package/lib/operations/update.js.map +1 -1
  132. package/lib/operations/validate_collection.js +6 -5
  133. package/lib/operations/validate_collection.js.map +1 -1
  134. package/lib/promise_provider.js +1 -1
  135. package/lib/promise_provider.js.map +1 -1
  136. package/lib/read_preference.js +8 -8
  137. package/lib/read_preference.js.map +1 -1
  138. package/lib/sdam/common.js +12 -10
  139. package/lib/sdam/common.js.map +1 -1
  140. package/lib/sdam/server.js +90 -25
  141. package/lib/sdam/server.js.map +1 -1
  142. package/lib/sdam/server_description.js +9 -4
  143. package/lib/sdam/server_description.js.map +1 -1
  144. package/lib/sdam/server_selection.js +10 -4
  145. package/lib/sdam/server_selection.js.map +1 -1
  146. package/lib/sdam/srv_polling.js +1 -1
  147. package/lib/sdam/srv_polling.js.map +1 -1
  148. package/lib/sdam/topology.js +42 -21
  149. package/lib/sdam/topology.js.map +1 -1
  150. package/lib/sdam/topology_description.js +7 -3
  151. package/lib/sdam/topology_description.js.map +1 -1
  152. package/lib/sessions.js +132 -31
  153. package/lib/sessions.js.map +1 -1
  154. package/lib/sort.js +3 -3
  155. package/lib/sort.js.map +1 -1
  156. package/lib/transactions.js +15 -7
  157. package/lib/transactions.js.map +1 -1
  158. package/lib/utils.js +60 -20
  159. package/lib/utils.js.map +1 -1
  160. package/mongodb.d.ts +523 -138
  161. package/mongodb.ts34.d.ts +480 -141
  162. package/package.json +44 -48
  163. package/src/bson.ts +1 -0
  164. package/src/bulk/common.ts +83 -43
  165. package/src/bulk/ordered.ts +4 -3
  166. package/src/bulk/unordered.ts +4 -3
  167. package/src/change_stream.ts +46 -29
  168. package/src/cmap/auth/auth_provider.ts +3 -2
  169. package/src/cmap/auth/gssapi.ts +15 -5
  170. package/src/cmap/auth/mongo_credentials.ts +22 -8
  171. package/src/cmap/auth/mongocr.ts +3 -3
  172. package/src/cmap/auth/mongodb_aws.ts +52 -39
  173. package/src/cmap/auth/plain.ts +2 -2
  174. package/src/cmap/auth/scram.ts +23 -13
  175. package/src/cmap/auth/x509.ts +3 -3
  176. package/src/cmap/command_monitoring_events.ts +36 -14
  177. package/src/cmap/commands.ts +12 -6
  178. package/src/cmap/connect.ts +42 -12
  179. package/src/cmap/connection.ts +54 -62
  180. package/src/cmap/connection_pool.ts +141 -20
  181. package/src/cmap/connection_pool_events.ts +8 -1
  182. package/src/cmap/errors.ts +3 -4
  183. package/src/cmap/message_stream.ts +2 -4
  184. package/src/cmap/metrics.ts +58 -0
  185. package/src/cmap/stream_description.ts +6 -1
  186. package/src/cmap/wire_protocol/compression.ts +26 -13
  187. package/src/cmap/wire_protocol/shared.ts +4 -2
  188. package/src/collection.ts +75 -70
  189. package/src/connection_string.ts +97 -34
  190. package/src/cursor/abstract_cursor.ts +141 -104
  191. package/src/cursor/aggregation_cursor.ts +34 -20
  192. package/src/cursor/find_cursor.ts +41 -21
  193. package/src/db.ts +19 -18
  194. package/src/deps.ts +110 -22
  195. package/src/encrypter.ts +6 -12
  196. package/src/error.ts +264 -48
  197. package/src/explain.ts +3 -3
  198. package/src/gridfs/download.ts +48 -53
  199. package/src/gridfs/index.ts +5 -4
  200. package/src/gridfs/upload.ts +32 -33
  201. package/src/index.ts +42 -4
  202. package/src/logger.ts +6 -3
  203. package/src/mongo_client.ts +20 -23
  204. package/src/mongo_types.ts +19 -20
  205. package/src/operations/add_user.ts +4 -5
  206. package/src/operations/aggregate.ts +18 -17
  207. package/src/operations/command.ts +7 -10
  208. package/src/operations/common_functions.ts +2 -3
  209. package/src/operations/connect.ts +4 -3
  210. package/src/operations/count.ts +2 -2
  211. package/src/operations/count_documents.ts +2 -2
  212. package/src/operations/delete.ts +8 -6
  213. package/src/operations/distinct.ts +5 -3
  214. package/src/operations/estimated_document_count.ts +5 -1
  215. package/src/operations/eval.ts +1 -1
  216. package/src/operations/execute_operation.ts +41 -20
  217. package/src/operations/find.ts +25 -16
  218. package/src/operations/find_and_modify.ts +12 -10
  219. package/src/operations/indexes.ts +39 -8
  220. package/src/operations/insert.ts +7 -4
  221. package/src/operations/is_capped.ts +3 -2
  222. package/src/operations/list_collections.ts +9 -6
  223. package/src/operations/map_reduce.ts +4 -2
  224. package/src/operations/operation.ts +7 -2
  225. package/src/operations/options_operation.ts +3 -2
  226. package/src/operations/profiling_level.ts +5 -3
  227. package/src/operations/set_profiling_level.ts +9 -3
  228. package/src/operations/update.ts +17 -13
  229. package/src/operations/validate_collection.ts +7 -6
  230. package/src/promise_provider.ts +2 -2
  231. package/src/read_preference.ts +11 -9
  232. package/src/sdam/common.ts +11 -9
  233. package/src/sdam/server.ts +168 -69
  234. package/src/sdam/server_description.ts +16 -4
  235. package/src/sdam/server_selection.ts +15 -7
  236. package/src/sdam/srv_polling.ts +2 -2
  237. package/src/sdam/topology.ts +67 -36
  238. package/src/sdam/topology_description.ts +11 -4
  239. package/src/sessions.ts +194 -37
  240. package/src/sort.ts +6 -4
  241. package/src/transactions.ts +18 -9
  242. package/src/utils.ts +73 -20
  243. package/HISTORY.md +0 -2993
  244. package/lib/operations/find_one.js +0 -34
  245. package/lib/operations/find_one.js.map +0 -1
  246. package/src/operations/find_one.ts +0 -43
package/mongodb.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+
2
3
  import { Binary } from 'bson';
3
4
  import { BSONRegExp } from 'bson';
4
5
  import { BSONSymbol } from 'bson';
@@ -58,33 +59,41 @@ export declare abstract class AbstractCursor<TSchema = any, CursorEvents extends
58
59
  /* Excluded from this release type: cursorOptions */
59
60
  get closed(): boolean;
60
61
  get killed(): boolean;
62
+ get loadBalanced(): boolean;
61
63
  /** Returns current buffered documents length */
62
64
  bufferedCount(): number;
63
65
  /** Returns current buffered documents */
64
66
  readBufferedDocuments(number?: number): TSchema[];
65
- [Symbol.asyncIterator](): AsyncIterator<TSchema | null>;
67
+ [Symbol.asyncIterator](): AsyncIterator<TSchema, void>;
66
68
  stream(options?: CursorStreamOptions): Readable;
67
69
  hasNext(): Promise<boolean>;
68
70
  hasNext(callback: Callback<boolean>): void;
69
71
  /** Get the next available document from the cursor, returns null if no more documents are available. */
70
- next<T = TSchema>(): Promise<T | null>;
71
- next<T = TSchema>(callback: Callback<T | null>): void;
72
+ next(): Promise<TSchema | null>;
73
+ next(callback: Callback<TSchema | null>): void;
74
+ next(callback?: Callback<TSchema | null>): Promise<TSchema | null> | void;
72
75
  /**
73
76
  * Try to get the next available document from the cursor or `null` if an empty batch is returned
74
77
  */
75
- tryNext<T = TSchema>(): Promise<T | null>;
76
- tryNext<T = TSchema>(callback: Callback<T | null>): void;
78
+ tryNext(): Promise<TSchema | null>;
79
+ tryNext(callback: Callback<TSchema | null>): void;
77
80
  /**
78
81
  * Iterates over all the documents for this cursor using the iterator, callback pattern.
79
82
  *
80
83
  * @param iterator - The iteration callback.
81
84
  * @param callback - The end callback.
82
85
  */
83
- forEach<T = TSchema>(iterator: (doc: T) => boolean | void): Promise<void>;
84
- forEach<T = TSchema>(iterator: (doc: T) => boolean | void, callback: Callback<void>): void;
86
+ forEach(iterator: (doc: TSchema) => boolean | void): Promise<void>;
87
+ forEach(iterator: (doc: TSchema) => boolean | void, callback: Callback<void>): void;
85
88
  close(): void;
86
89
  close(callback: Callback): void;
90
+ /**
91
+ * @deprecated options argument is deprecated
92
+ */
87
93
  close(options: CursorCloseOptions): Promise<void>;
94
+ /**
95
+ * @deprecated options argument is deprecated
96
+ */
88
97
  close(options: CursorCloseOptions, callback: Callback): void;
89
98
  /**
90
99
  * Returns an array of documents. The caller is responsible for making sure that there
@@ -94,8 +103,8 @@ export declare abstract class AbstractCursor<TSchema = any, CursorEvents extends
94
103
  *
95
104
  * @param callback - The result callback.
96
105
  */
97
- toArray<T = TSchema>(): Promise<T[]>;
98
- toArray<T = TSchema>(callback: Callback<T[]>): void;
106
+ toArray(): Promise<TSchema[]>;
107
+ toArray(callback: Callback<TSchema[]>): void;
99
108
  /**
100
109
  * Add a cursor flag to the cursor
101
110
  *
@@ -107,11 +116,12 @@ export declare abstract class AbstractCursor<TSchema = any, CursorEvents extends
107
116
  * Map all documents using the provided function
108
117
  * If there is a transform set on the cursor, that will be called first and the result passed to
109
118
  * this function's transform.
110
- * @remarks
111
119
  *
112
- * **NOTE:** adding a transform changes the return type of the iteration of this cursor, it **does not** return
113
- * a new instance of a cursor. This means when calling map, you should always assign the result to a new
114
- * variable. Take note of the following example:
120
+ * @remarks
121
+ * **Note for Typescript Users:** adding a transform changes the return type of the iteration of this cursor,
122
+ * it **does not** return a new instance of a cursor. This means when calling map,
123
+ * you should always assign the result to a new variable in order to get a correctly typed cursor variable.
124
+ * Take note of the following example:
115
125
  *
116
126
  * @example
117
127
  * ```typescript
@@ -379,7 +389,6 @@ export declare interface AggregateOptions extends CommandOperationOptions {
379
389
  * @public
380
390
  */
381
391
  export declare class AggregationCursor<TSchema = Document> extends AbstractCursor<TSchema> {
382
- /* Excluded from this release type: [kParent] */
383
392
  /* Excluded from this release type: [kPipeline] */
384
393
  /* Excluded from this release type: [kOptions] */
385
394
  /* Excluded from this release type: __constructor */
@@ -397,8 +406,11 @@ export declare class AggregationCursor<TSchema = Document> extends AbstractCurso
397
406
  limit($limit: number): this;
398
407
  /** Add a match stage to the aggregation pipeline */
399
408
  match($match: Document): this;
400
- /** Add a out stage to the aggregation pipeline */
401
- out($out: number): this;
409
+ /** Add an out stage to the aggregation pipeline */
410
+ out($out: {
411
+ db: string;
412
+ coll: string;
413
+ } | string): this;
402
414
  /**
403
415
  * Add a project stage to the aggregation pipeline
404
416
  *
@@ -406,18 +418,41 @@ export declare class AggregationCursor<TSchema = Document> extends AbstractCurso
406
418
  * In order to strictly type this function you must provide an interface
407
419
  * that represents the effect of your projection on the result documents.
408
420
  *
409
- * **NOTE:** adding a projection changes the return type of the iteration of this cursor,
421
+ * By default chaining a projection to your cursor changes the returned type to the generic {@link Document} type.
422
+ * You should specify a parameterized type to have assertions on your final results.
423
+ *
424
+ * @example
425
+ * ```typescript
426
+ * // Best way
427
+ * const docs: AggregationCursor<{ a: number }> = cursor.project<{ a: number }>({ _id: 0, a: true });
428
+ * // Flexible way
429
+ * const docs: AggregationCursor<Document> = cursor.project({ _id: 0, a: true });
430
+ * ```
431
+ *
432
+ * @remarks
433
+ * In order to strictly type this function you must provide an interface
434
+ * that represents the effect of your projection on the result documents.
435
+ *
436
+ * **Note for Typescript Users:** adding a transform changes the return type of the iteration of this cursor,
410
437
  * it **does not** return a new instance of a cursor. This means when calling project,
411
- * you should always assign the result to a new variable. Take note of the following example:
438
+ * you should always assign the result to a new variable in order to get a correctly typed cursor variable.
439
+ * Take note of the following example:
412
440
  *
413
441
  * @example
414
442
  * ```typescript
415
443
  * const cursor: AggregationCursor<{ a: number; b: string }> = coll.aggregate([]);
416
- * const projectCursor = cursor.project<{ a: number }>({ a: true });
444
+ * const projectCursor = cursor.project<{ a: number }>({ _id: 0, a: true });
417
445
  * const aPropOnlyArray: {a: number}[] = await projectCursor.toArray();
446
+ *
447
+ * // or always use chaining and save the final cursor
448
+ *
449
+ * const cursor = coll.aggregate().project<{ a: string }>({
450
+ * _id: 0,
451
+ * a: { $convert: { input: '$a', to: 'string' }
452
+ * }});
418
453
  * ```
419
454
  */
420
- project<T = TSchema>($project: Projection<T>): AggregationCursor<T>;
455
+ project<T extends Document = Document>($project: Document): AggregationCursor<T>;
421
456
  /** Add a lookup stage to the aggregation pipeline */
422
457
  lookup($lookup: Document): this;
423
458
  /** Add a redact stage to the aggregation pipeline */
@@ -493,6 +528,14 @@ export declare const AuthMechanism: Readonly<{
493
528
  /** @public */
494
529
  export declare type AuthMechanism = typeof AuthMechanism[keyof typeof AuthMechanism];
495
530
 
531
+ /** @public */
532
+ export declare interface AuthMechanismProperties extends Document {
533
+ SERVICE_NAME?: string;
534
+ SERVICE_REALM?: string;
535
+ CANONICALIZE_HOST_NAME?: boolean;
536
+ AWS_SESSION_TOKEN?: string;
537
+ }
538
+
496
539
  /** @public */
497
540
  export declare interface AutoEncrypter {
498
541
  new (client: MongoClient, options: AutoEncryptionOptions): AutoEncrypter;
@@ -629,10 +672,12 @@ export declare const BatchType: Readonly<{
629
672
 
630
673
  /** @public */
631
674
  export declare type BatchType = typeof BatchType[keyof typeof BatchType];
675
+
632
676
  export { Binary }
633
677
 
634
678
  /** @public */
635
- export declare type BitwiseFilter = number /** numeric bit mask */ | Binary /** BinData bit mask */ | number[];
679
+ export declare type BitwiseFilter = number /** numeric bit mask */ | Binary /** BinData bit mask */ | ReadonlyArray<number>;
680
+
636
681
  export { BSONRegExp }
637
682
 
638
683
  /**
@@ -643,6 +688,7 @@ export declare interface BSONSerializeOptions extends Omit<SerializeOptions, 'in
643
688
  /** Return BSON filled buffers from operations */
644
689
  raw?: boolean;
645
690
  }
691
+
646
692
  export { BSONSymbol }
647
693
 
648
694
  /** @public */
@@ -769,6 +815,7 @@ export declare interface BulkWriteOperationError {
769
815
  index: number;
770
816
  code: number;
771
817
  errmsg: string;
818
+ errInfo: Document;
772
819
  op: Document | UpdateStatement | DeleteStatement;
773
820
  }
774
821
 
@@ -1061,12 +1108,18 @@ export declare class ClientSession extends TypedEventEmitter<ClientSessionEvents
1061
1108
  /* Excluded from this release type: [kServerSession] */
1062
1109
  /* Excluded from this release type: [kSnapshotTime] */
1063
1110
  /* Excluded from this release type: [kSnapshotEnabled] */
1111
+ /* Excluded from this release type: [kPinnedConnection] */
1064
1112
  /* Excluded from this release type: __constructor */
1065
1113
  /** The server id associated with this session */
1066
1114
  get id(): ServerSessionId | undefined;
1067
1115
  get serverSession(): ServerSession;
1068
1116
  /** Whether or not this session is configured for snapshot reads */
1069
1117
  get snapshotEnabled(): boolean;
1118
+ get loadBalanced(): boolean;
1119
+ /* Excluded from this release type: pinnedConnection */
1120
+ /* Excluded from this release type: pin */
1121
+ /* Excluded from this release type: unpin */
1122
+ get isPinned(): boolean;
1070
1123
  /**
1071
1124
  * Ends this session on the server
1072
1125
  *
@@ -1075,14 +1128,20 @@ export declare class ClientSession extends TypedEventEmitter<ClientSessionEvents
1075
1128
  */
1076
1129
  endSession(): Promise<void>;
1077
1130
  endSession(callback: Callback<void>): void;
1078
- endSession(options: Record<string, unknown>): Promise<void>;
1079
- endSession(options: Record<string, unknown>, callback: Callback<void>): void;
1131
+ endSession(options: EndSessionOptions): Promise<void>;
1132
+ endSession(options: EndSessionOptions, callback: Callback<void>): void;
1080
1133
  /**
1081
1134
  * Advances the operationTime for a ClientSession.
1082
1135
  *
1083
1136
  * @param operationTime - the `BSON.Timestamp` of the operation type it is desired to advance to
1084
1137
  */
1085
1138
  advanceOperationTime(operationTime: Timestamp): void;
1139
+ /**
1140
+ * Advances the clusterTime for a ClientSession to the provided clusterTime of another ClientSession
1141
+ *
1142
+ * @param clusterTime - the $clusterTime returned by the server from another session in the form of a document containing the `BSON.Timestamp` clusterTime and signature
1143
+ */
1144
+ advanceClusterTime(clusterTime: ClusterTime): void;
1086
1145
  /**
1087
1146
  * Used to determine if this session equals another
1088
1147
  *
@@ -1162,6 +1221,7 @@ export declare interface ClusterTime {
1162
1221
  keyId: Long;
1163
1222
  };
1164
1223
  }
1224
+
1165
1225
  export { Code }
1166
1226
 
1167
1227
  /** @public */
@@ -1308,10 +1368,10 @@ export declare class Collection<TSchema extends Document = Document> {
1308
1368
  * @param options - Optional settings for the command
1309
1369
  * @param callback - An optional callback, a Promise will be returned if none is provided
1310
1370
  */
1311
- updateOne(filter: Filter<TSchema>, update: UpdateFilter<TSchema> | Partial<TSchema>): Promise<UpdateResult | Document>;
1312
- updateOne(filter: Filter<TSchema>, update: UpdateFilter<TSchema> | Partial<TSchema>, callback: Callback<UpdateResult | Document>): void;
1313
- updateOne(filter: Filter<TSchema>, update: UpdateFilter<TSchema> | Partial<TSchema>, options: UpdateOptions): Promise<UpdateResult | Document>;
1314
- updateOne(filter: Filter<TSchema>, update: UpdateFilter<TSchema> | Partial<TSchema>, options: UpdateOptions, callback: Callback<UpdateResult | Document>): void;
1371
+ updateOne(filter: Filter<TSchema>, update: UpdateFilter<TSchema> | Partial<TSchema>): Promise<UpdateResult>;
1372
+ updateOne(filter: Filter<TSchema>, update: UpdateFilter<TSchema> | Partial<TSchema>, callback: Callback<UpdateResult>): void;
1373
+ updateOne(filter: Filter<TSchema>, update: UpdateFilter<TSchema> | Partial<TSchema>, options: UpdateOptions): Promise<UpdateResult>;
1374
+ updateOne(filter: Filter<TSchema>, update: UpdateFilter<TSchema> | Partial<TSchema>, options: UpdateOptions, callback: Callback<UpdateResult>): void;
1315
1375
  /**
1316
1376
  * Replace a document in a collection with another document
1317
1377
  *
@@ -1370,7 +1430,7 @@ export declare class Collection<TSchema extends Document = Document> {
1370
1430
  */
1371
1431
  rename(newName: string): Promise<Collection>;
1372
1432
  rename(newName: string, callback: Callback<Collection>): void;
1373
- rename(newName: string, options: RenameOptions): Promise<Collection> | void;
1433
+ rename(newName: string, options: RenameOptions): Promise<Collection>;
1374
1434
  rename(newName: string, options: RenameOptions, callback: Callback<Collection>): void;
1375
1435
  /**
1376
1436
  * Drop the collection from the database, removing it permanently. New accesses will create a new collection.
@@ -1389,25 +1449,25 @@ export declare class Collection<TSchema extends Document = Document> {
1389
1449
  * @param options - Optional settings for the command
1390
1450
  * @param callback - An optional callback, a Promise will be returned if none is provided
1391
1451
  */
1392
- findOne(): Promise<TSchema | undefined>;
1393
- findOne(callback: Callback<TSchema | undefined>): void;
1394
- findOne(filter: Filter<TSchema>): Promise<TSchema | undefined>;
1395
- findOne(filter: Filter<TSchema>, callback: Callback<TSchema | undefined>): void;
1396
- findOne(filter: Filter<TSchema>, options: FindOptions<TSchema>): Promise<TSchema | undefined>;
1397
- findOne(filter: Filter<TSchema>, options: FindOptions<TSchema>, callback: Callback<TSchema | undefined>): void;
1398
- findOne<T = TSchema>(): Promise<T | undefined>;
1399
- findOne<T = TSchema>(callback: Callback<T | undefined>): void;
1400
- findOne<T = TSchema>(filter: Filter<T>): Promise<T | undefined>;
1401
- findOne<T = TSchema>(filter: Filter<T>, options?: FindOptions<T>): Promise<T | undefined>;
1402
- findOne<T = TSchema>(filter: Filter<T>, options?: FindOptions<T>, callback?: Callback<T | undefined>): void;
1452
+ findOne(): Promise<TSchema | null>;
1453
+ findOne(callback: Callback<TSchema | null>): void;
1454
+ findOne(filter: Filter<TSchema>): Promise<TSchema | null>;
1455
+ findOne(filter: Filter<TSchema>, callback: Callback<TSchema | null>): void;
1456
+ findOne(filter: Filter<TSchema>, options: FindOptions): Promise<TSchema | null>;
1457
+ findOne(filter: Filter<TSchema>, options: FindOptions, callback: Callback<TSchema | null>): void;
1458
+ findOne<T = TSchema>(): Promise<T | null>;
1459
+ findOne<T = TSchema>(callback: Callback<T | null>): void;
1460
+ findOne<T = TSchema>(filter: Filter<TSchema>): Promise<T | null>;
1461
+ findOne<T = TSchema>(filter: Filter<TSchema>, options?: FindOptions): Promise<T | null>;
1462
+ findOne<T = TSchema>(filter: Filter<TSchema>, options?: FindOptions, callback?: Callback<T | null>): void;
1403
1463
  /**
1404
1464
  * Creates a cursor for a filter that can be used to iterate over results from MongoDB
1405
1465
  *
1406
1466
  * @param filter - The filter predicate. If unspecified, then all documents in the collection will match the predicate
1407
1467
  */
1408
1468
  find(): FindCursor<TSchema>;
1409
- find(filter: Filter<TSchema>, options?: FindOptions<TSchema>): FindCursor<TSchema>;
1410
- find<T = TSchema>(filter: Filter<T>, options?: FindOptions<T>): FindCursor<T>;
1469
+ find(filter: Filter<TSchema>, options?: FindOptions): FindCursor<TSchema>;
1470
+ find<T>(filter: Filter<TSchema>, options?: FindOptions): FindCursor<T>;
1411
1471
  /**
1412
1472
  * Returns the options of the collection.
1413
1473
  *
@@ -1614,10 +1674,10 @@ export declare class Collection<TSchema extends Document = Document> {
1614
1674
  * @param options - Optional settings for the command
1615
1675
  * @param callback - An optional callback, a Promise will be returned if none is provided
1616
1676
  */
1617
- indexes(): Promise<Document>;
1618
- indexes(callback: Callback<Document>): void;
1619
- indexes(options: IndexInformationOptions): Promise<Document>;
1620
- indexes(options: IndexInformationOptions, callback: Callback<Document>): void;
1677
+ indexes(): Promise<Document[]>;
1678
+ indexes(callback: Callback<Document[]>): void;
1679
+ indexes(options: IndexInformationOptions): Promise<Document[]>;
1680
+ indexes(options: IndexInformationOptions, callback: Callback<Document[]>): void;
1621
1681
  /**
1622
1682
  * Get all the collection statistics.
1623
1683
  *
@@ -1636,8 +1696,8 @@ export declare class Collection<TSchema extends Document = Document> {
1636
1696
  * @param callback - An optional callback, a Promise will be returned if none is provided
1637
1697
  */
1638
1698
  findOneAndDelete(filter: Filter<TSchema>): Promise<ModifyResult<TSchema>>;
1639
- findOneAndDelete(filter: Filter<TSchema>, callback: Callback<ModifyResult<TSchema>>): void;
1640
1699
  findOneAndDelete(filter: Filter<TSchema>, options: FindOneAndDeleteOptions): Promise<ModifyResult<TSchema>>;
1700
+ findOneAndDelete(filter: Filter<TSchema>, callback: Callback<ModifyResult<TSchema>>): void;
1641
1701
  findOneAndDelete(filter: Filter<TSchema>, options: FindOneAndDeleteOptions, callback: Callback<ModifyResult<TSchema>>): void;
1642
1702
  /**
1643
1703
  * Find a document and replace it in one atomic operation. Requires a write lock for the duration of the operation.
@@ -1842,14 +1902,16 @@ export declare class CommandFailedEvent {
1842
1902
  duration: number;
1843
1903
  commandName: string;
1844
1904
  failure: Error;
1905
+ serviceId?: ObjectId;
1845
1906
  /* Excluded from this release type: __constructor */
1907
+ get hasServiceId(): boolean;
1846
1908
  }
1847
1909
 
1848
1910
  /* Excluded from this release type: CommandOperation */
1849
1911
 
1850
1912
  /** @public */
1851
1913
  export declare interface CommandOperationOptions extends OperationOptions, WriteConcernOptions, ExplainOptions {
1852
- /** Return the full server response for the command */
1914
+ /** @deprecated This option does nothing */
1853
1915
  fullResponse?: boolean;
1854
1916
  /** Specify a read concern and level for the collection. (only MongoDB 3.2 or higher supported) */
1855
1917
  readConcern?: ReadConcernLike;
@@ -1865,23 +1927,7 @@ export declare interface CommandOperationOptions extends OperationOptions, Write
1865
1927
  noResponse?: boolean;
1866
1928
  }
1867
1929
 
1868
- /** @public */
1869
- export declare interface CommandOptions extends BSONSerializeOptions {
1870
- command?: boolean;
1871
- slaveOk?: boolean;
1872
- /** Specify read preference if command supports it */
1873
- readPreference?: ReadPreferenceLike;
1874
- raw?: boolean;
1875
- monitoring?: boolean;
1876
- fullResult?: boolean;
1877
- socketTimeoutMS?: number;
1878
- /** Session to use for the operation */
1879
- session?: ClientSession;
1880
- documentsReturnedIn?: string;
1881
- noResponse?: boolean;
1882
- willRetryWrite?: boolean;
1883
- writeConcern?: WriteConcernOptions | WriteConcern | W;
1884
- }
1930
+ /* Excluded from this release type: CommandOptions */
1885
1931
 
1886
1932
  /**
1887
1933
  * An event indicating the start of a given
@@ -1896,7 +1942,9 @@ export declare class CommandStartedEvent {
1896
1942
  command: Document;
1897
1943
  address: string;
1898
1944
  connectionId?: string | number;
1945
+ serviceId?: ObjectId;
1899
1946
  /* Excluded from this release type: __constructor */
1947
+ get hasServiceId(): boolean;
1900
1948
  }
1901
1949
 
1902
1950
  /**
@@ -1911,7 +1959,9 @@ export declare class CommandSucceededEvent {
1911
1959
  duration: number;
1912
1960
  commandName: string;
1913
1961
  reply: unknown;
1962
+ serviceId?: ObjectId;
1914
1963
  /* Excluded from this release type: __constructor */
1964
+ get hasServiceId(): boolean;
1915
1965
  }
1916
1966
 
1917
1967
  /** @public */
@@ -1987,6 +2037,7 @@ export declare class ConnectionClosedEvent extends ConnectionPoolMonitoringEvent
1987
2037
  connectionId: number | '<monitor>';
1988
2038
  /** The reason the connection was closed */
1989
2039
  reason: string;
2040
+ serviceId?: ObjectId;
1990
2041
  /* Excluded from this release type: __constructor */
1991
2042
  }
1992
2043
 
@@ -2009,6 +2060,8 @@ export declare type ConnectionEvents = {
2009
2060
  clusterTimeReceived(clusterTime: Document): void;
2010
2061
  close(): void;
2011
2062
  message(message: any): void;
2063
+ pinned(pinType: string): void;
2064
+ unpinned(pinType: string): void;
2012
2065
  };
2013
2066
 
2014
2067
  /** @public */
@@ -2039,6 +2092,7 @@ export declare interface ConnectionOptions extends SupportedNodeConnectionOption
2039
2092
  * @category Event
2040
2093
  */
2041
2094
  export declare class ConnectionPoolClearedEvent extends ConnectionPoolMonitoringEvent {
2095
+ /* Excluded from this release type: serviceId */
2042
2096
  /* Excluded from this release type: __constructor */
2043
2097
  }
2044
2098
 
@@ -2076,6 +2130,8 @@ export declare type ConnectionPoolEvents = {
2076
2130
  connectionCheckedIn(event: ConnectionCheckedInEvent): void;
2077
2131
  } & Omit<ConnectionEvents, 'close' | 'message'>;
2078
2132
 
2133
+ /* Excluded from this release type: ConnectionPoolMetrics */
2134
+
2079
2135
  /**
2080
2136
  * The base export class for all monitoring events published from the connection pool
2081
2137
  * @public
@@ -2099,6 +2155,8 @@ export declare interface ConnectionPoolOptions extends Omit<ConnectionOptions, '
2099
2155
  maxIdleTimeMS: number;
2100
2156
  /** The maximum amount of time operation execution should wait for a connection to become available. The default is 0 which means there is no limit. */
2101
2157
  waitQueueTimeoutMS: number;
2158
+ /** If we are in load balancer mode. */
2159
+ loadBalanced: boolean;
2102
2160
  }
2103
2161
 
2104
2162
  /**
@@ -2187,9 +2245,12 @@ export declare interface CreateIndexesOptions extends CommandOperationOptions {
2187
2245
  sparse?: boolean;
2188
2246
  /** Allows you to expire data on indexes applied to a data (MongoDB 2.2 or higher) */
2189
2247
  expireAfterSeconds?: number;
2248
+ /** Allows users to configure the storage engine on a per-index basis when creating an index. (MongoDB 3.0 or higher) */
2190
2249
  storageEngine?: Document;
2191
2250
  /** (MongoDB 4.4. or higher) Specifies how many data-bearing members of a replica set, including the primary, must complete the index builds successfully before the primary marks the indexes as ready. This option accepts the same values for the "w" field in a write concern plus "votingMembers", which indicates all voting data-bearing nodes. */
2192
2251
  commitQuorum?: number | string;
2252
+ /** Specifies the index version number, either 0 or 1. */
2253
+ version?: number;
2193
2254
  weights?: Document;
2194
2255
  default_language?: string;
2195
2256
  language_override?: string;
@@ -2202,14 +2263,18 @@ export declare interface CreateIndexesOptions extends CommandOperationOptions {
2202
2263
  max?: number;
2203
2264
  bucketSize?: number;
2204
2265
  wildcardProjection?: Document;
2266
+ /** Specifies that the index should exist on the target collection but should not be used by the query planner when executing operations. (MongoDB 4.4 or higher) */
2267
+ hidden?: boolean;
2205
2268
  }
2206
2269
 
2207
2270
  /** @public */
2208
2271
  export declare const CURSOR_FLAGS: readonly ["tailable", "oplogReplay", "noCursorTimeout", "awaitData", "exhaust", "partial"];
2209
2272
 
2210
- /** @public */
2273
+ /** @public
2274
+ * @deprecated This interface is deprecated */
2211
2275
  export declare interface CursorCloseOptions {
2212
2276
  /** Bypass calling killCursors when closing the cursor. */
2277
+ /** @deprecated the skipKillCursors option is deprecated */
2213
2278
  skipKillCursors?: boolean;
2214
2279
  }
2215
2280
 
@@ -2301,7 +2366,7 @@ export declare class Db {
2301
2366
  * @param pipeline - An array of aggregation stages to be executed
2302
2367
  * @param options - Optional settings for the command
2303
2368
  */
2304
- aggregate(pipeline?: Document[], options?: AggregateOptions): AggregationCursor;
2369
+ aggregate<T = Document>(pipeline?: Document[], options?: AggregateOptions): AggregationCursor<T>;
2305
2370
  /** Return the Admin db instance */
2306
2371
  admin(): Admin;
2307
2372
  /**
@@ -2310,7 +2375,7 @@ export declare class Db {
2310
2375
  * @param name - the collection name we wish to access.
2311
2376
  * @returns return the new Collection instance
2312
2377
  */
2313
- collection<TSchema extends Document = Document>(name: string): Collection<TSchema>;
2378
+ collection<TSchema extends Document = Document>(name: string, options?: CollectionOptions): Collection<TSchema>;
2314
2379
  /**
2315
2380
  * Get all the db statistics.
2316
2381
  *
@@ -2451,7 +2516,10 @@ export declare class Db {
2451
2516
  indexInformation(name: string, callback: Callback<Document>): void;
2452
2517
  indexInformation(name: string, options: IndexInformationOptions): Promise<Document>;
2453
2518
  indexInformation(name: string, options: IndexInformationOptions, callback: Callback<Document>): void;
2454
- /** Unref all sockets */
2519
+ /**
2520
+ * Unref all sockets
2521
+ * @deprecated This function is deprecated and will be removed in the next major version.
2522
+ */
2455
2523
  unref(): void;
2456
2524
  /**
2457
2525
  * Create a new Change Stream, watching for new changes (insertions, updates,
@@ -2493,6 +2561,7 @@ export declare interface DbStatsOptions extends CommandOperationOptions {
2493
2561
  /** Divide the returned sizes by scale value. */
2494
2562
  scale?: number;
2495
2563
  }
2564
+
2496
2565
  export { Decimal128 }
2497
2566
 
2498
2567
  /** @public */
@@ -2563,7 +2632,9 @@ export declare interface DestroyOptions {
2563
2632
 
2564
2633
  /** @public */
2565
2634
  export declare type DistinctOptions = CommandOperationOptions;
2635
+
2566
2636
  export { Document }
2637
+
2567
2638
  export { Double }
2568
2639
 
2569
2640
  /** @public */
@@ -2586,16 +2657,23 @@ export declare type DropIndexesOptions = CommandOperationOptions;
2586
2657
 
2587
2658
  /* Excluded from this release type: EncrypterOptions */
2588
2659
 
2660
+ /** @public */
2661
+ export declare interface EndSessionOptions {
2662
+ /* Excluded from this release type: error */
2663
+ force?: boolean;
2664
+ forceClear?: boolean;
2665
+ }
2666
+
2589
2667
  /** TypeScript Omit (Exclude to be specific) does not work for objects with an "any" indexed type, and breaks discriminated unions @public */
2590
2668
  export declare type EnhancedOmit<TRecordOrUnion, KeyUnion> = string extends keyof TRecordOrUnion ? TRecordOrUnion : TRecordOrUnion extends any ? Pick<TRecordOrUnion, Exclude<keyof TRecordOrUnion, KeyUnion>> : never;
2591
2669
 
2592
2670
  /** @public */
2593
- export declare interface ErrorDescription {
2671
+ export declare interface ErrorDescription extends Document {
2594
2672
  message?: string;
2595
2673
  errmsg?: string;
2596
2674
  $err?: string;
2597
2675
  errorLabels?: string[];
2598
- [key: string]: any;
2676
+ errInfo?: Document;
2599
2677
  }
2600
2678
 
2601
2679
  /** @public */
@@ -2668,11 +2746,11 @@ export declare interface FilterOperators<TValue> extends Document {
2668
2746
  $eq?: TValue;
2669
2747
  $gt?: TValue;
2670
2748
  $gte?: TValue;
2671
- $in?: TValue[];
2749
+ $in?: ReadonlyArray<TValue>;
2672
2750
  $lt?: TValue;
2673
2751
  $lte?: TValue;
2674
2752
  $ne?: TValue;
2675
- $nin?: TValue[];
2753
+ $nin?: ReadonlyArray<TValue>;
2676
2754
  $not?: TValue extends string ? FilterOperators<TValue> | RegExp : FilterOperators<TValue>;
2677
2755
  /**
2678
2756
  * When `true`, `$exists` matches the documents that contain the field,
@@ -2692,8 +2770,8 @@ export declare interface FilterOperators<TValue> extends Document {
2692
2770
  $near?: Document;
2693
2771
  $nearSphere?: Document;
2694
2772
  $maxDistance?: number;
2695
- $all?: TValue extends ReadonlyArray<any> ? any[] : never;
2696
- $elemMatch?: TValue extends ReadonlyArray<any> ? Document : never;
2773
+ $all?: ReadonlyArray<any>;
2774
+ $elemMatch?: Document;
2697
2775
  $size?: TValue extends ReadonlyArray<any> ? number : never;
2698
2776
  $bitsAllClear?: BitwiseFilter;
2699
2777
  $bitsAllSet?: BitwiseFilter;
@@ -2790,18 +2868,40 @@ export declare class FindCursor<TSchema = Document> extends AbstractCursor<TSche
2790
2868
  * In order to strictly type this function you must provide an interface
2791
2869
  * that represents the effect of your projection on the result documents.
2792
2870
  *
2793
- * **NOTE:** adding a projection changes the return type of the iteration of this cursor,
2871
+ * By default chaining a projection to your cursor changes the returned type to the generic
2872
+ * {@link Document} type.
2873
+ * You should specify a parameterized type to have assertions on your final results.
2874
+ *
2875
+ * @example
2876
+ * ```typescript
2877
+ * // Best way
2878
+ * const docs: FindCursor<{ a: number }> = cursor.project<{ a: number }>({ _id: 0, a: true });
2879
+ * // Flexible way
2880
+ * const docs: FindCursor<Document> = cursor.project({ _id: 0, a: true });
2881
+ * ```
2882
+ *
2883
+ * @remarks
2884
+ *
2885
+ * **Note for Typescript Users:** adding a transform changes the return type of the iteration of this cursor,
2794
2886
  * it **does not** return a new instance of a cursor. This means when calling project,
2795
- * you should always assign the result to a new variable. Take note of the following example:
2887
+ * you should always assign the result to a new variable in order to get a correctly typed cursor variable.
2888
+ * Take note of the following example:
2796
2889
  *
2797
2890
  * @example
2798
2891
  * ```typescript
2799
2892
  * const cursor: FindCursor<{ a: number; b: string }> = coll.find();
2800
- * const projectCursor = cursor.project<{ a: number }>({ a: true });
2893
+ * const projectCursor = cursor.project<{ a: number }>({ _id: 0, a: true });
2801
2894
  * const aPropOnlyArray: {a: number}[] = await projectCursor.toArray();
2895
+ *
2896
+ * // or always use chaining and save the final cursor
2897
+ *
2898
+ * const cursor = coll.find().project<{ a: string }>({
2899
+ * _id: 0,
2900
+ * a: { $convert: { input: '$a', to: 'string' }
2901
+ * }});
2802
2902
  * ```
2803
2903
  */
2804
- project<T = TSchema>(value: Projection<T>): FindCursor<T>;
2904
+ project<T extends Document = Document>(value: Document): FindCursor<T>;
2805
2905
  /**
2806
2906
  * Sets the sort order of the cursor query.
2807
2907
  *
@@ -2913,14 +3013,17 @@ export declare class FindOperators {
2913
3013
  arrayFilters(arrayFilters: Document[]): this;
2914
3014
  }
2915
3015
 
2916
- /** @public */
2917
- export declare interface FindOptions<TSchema = Document> extends CommandOperationOptions {
3016
+ /**
3017
+ * @public
3018
+ * @typeParam TSchema - Unused schema definition, deprecated usage, only specify `FindOptions` with no generic
3019
+ */
3020
+ export declare interface FindOptions<TSchema extends Document = Document> extends CommandOperationOptions {
2918
3021
  /** Sets the limit of documents returned in the query. */
2919
3022
  limit?: number;
2920
3023
  /** Set to sort the documents coming back from the query. Array of indexes, `[['a', 1]]` etc. */
2921
3024
  sort?: Sort;
2922
3025
  /** The fields to return in the query. Object of fields to either include or exclude (one of, not both), `{'a':1, 'b': 1}` **or** `{'a': 0, 'b': 0}` */
2923
- projection?: Projection<TSchema>;
3026
+ projection?: Document;
2924
3027
  /** Set to skip N documents ahead in your query (useful for pagination). */
2925
3028
  skip?: number;
2926
3029
  /** Tell the query to use specific indexes in the query. Object of indexes to use, `{'_id':1}` */
@@ -3059,7 +3162,7 @@ export declare interface GridFSBucketOptions extends WriteConcernOptions {
3059
3162
  * Do not instantiate this class directly. Use `openDownloadStream()` instead.
3060
3163
  * @public
3061
3164
  */
3062
- export declare class GridFSBucketReadStream extends Readable {
3165
+ export declare class GridFSBucketReadStream extends Readable implements NodeJS.ReadableStream {
3063
3166
  /* Excluded from this release type: s */
3064
3167
  /**
3065
3168
  * An error occurred
@@ -3140,7 +3243,7 @@ export declare interface GridFSBucketReadStreamOptionsWithRevision extends GridF
3140
3243
  * Do not instantiate this class directly. Use `openUploadStream()` instead.
3141
3244
  * @public
3142
3245
  */
3143
- export declare class GridFSBucketWriteStream extends Writable {
3246
+ export declare class GridFSBucketWriteStream extends Writable implements NodeJS.WritableStream {
3144
3247
  bucket: GridFSBucket;
3145
3248
  chunks: Collection<GridFSChunk>;
3146
3249
  filename: string;
@@ -3178,10 +3281,10 @@ export declare class GridFSBucketWriteStream extends Writable {
3178
3281
  * @param callback - Function to call when the chunk was added to the buffer, or if the entire chunk was persisted to MongoDB if this chunk caused a flush.
3179
3282
  * @returns False if this write required flushing a chunk to MongoDB. True otherwise.
3180
3283
  */
3181
- write(chunk: Buffer): boolean;
3182
- write(chunk: Buffer, callback: Callback<void>): boolean;
3183
- write(chunk: Buffer, encoding: BufferEncoding | undefined): boolean;
3184
- write(chunk: Buffer, encoding: BufferEncoding | undefined, callback: Callback<void>): boolean;
3284
+ write(chunk: Buffer | string): boolean;
3285
+ write(chunk: Buffer | string, callback: Callback<void>): boolean;
3286
+ write(chunk: Buffer | string, encoding: BufferEncoding | undefined): boolean;
3287
+ write(chunk: Buffer | string, encoding: BufferEncoding | undefined, callback: Callback<void>): boolean;
3185
3288
  /**
3186
3289
  * Places this write stream into an aborted state (all future writes fail)
3187
3290
  * and deletes all chunks that have already been written.
@@ -3265,7 +3368,7 @@ export declare class HostAddress {
3265
3368
  }
3266
3369
 
3267
3370
  /** @public */
3268
- export declare interface IndexDescription {
3371
+ export declare interface IndexDescription extends Pick<CreateIndexesOptions, 'background' | 'unique' | 'partialFilterExpression' | 'sparse' | 'hidden' | 'expireAfterSeconds' | 'storageEngine' | 'version' | 'weights' | 'default_language' | 'language_override' | 'textIndexVersion' | '2dsphereIndexVersion' | 'bits' | 'min' | 'max' | 'bucketSize' | 'wildcardProjection'> {
3269
3372
  collation?: CollationOptions;
3270
3373
  name?: string;
3271
3374
  key: Document;
@@ -3326,6 +3429,7 @@ export declare interface InsertOneResult<TSchema = Document> {
3326
3429
  /** The identifier that was inserted. If the server generated the identifier, this value will be null as the driver does not have access to that data */
3327
3430
  insertedId: InferIdType<TSchema>;
3328
3431
  }
3432
+
3329
3433
  export { Int32 }
3330
3434
 
3331
3435
  /** @public */
@@ -3354,6 +3458,8 @@ export declare type IsAny<Type, ResultIfAny, ResultIfNotAny> = true extends fals
3354
3458
 
3355
3459
  /* Excluded from this release type: kCancelled_2 */
3356
3460
 
3461
+ /* Excluded from this release type: kCheckedOut */
3462
+
3357
3463
  /* Excluded from this release type: kClosed */
3358
3464
 
3359
3465
  /* Excluded from this release type: kClosed_2 */
@@ -3386,6 +3492,8 @@ export declare type KeysOfOtherType<TSchema, Type> = {
3386
3492
 
3387
3493
  /* Excluded from this release type: kFilter */
3388
3494
 
3495
+ /* Excluded from this release type: kFullResult */
3496
+
3389
3497
  /* Excluded from this release type: kGeneration */
3390
3498
 
3391
3499
  /* Excluded from this release type: kGeneration_2 */
@@ -3410,6 +3518,8 @@ export declare type KeysOfOtherType<TSchema, Type> = {
3410
3518
 
3411
3519
  /* Excluded from this release type: kMessageStream */
3412
3520
 
3521
+ /* Excluded from this release type: kMetrics */
3522
+
3413
3523
  /* Excluded from this release type: kMinPoolSizeTimer */
3414
3524
 
3415
3525
  /* Excluded from this release type: kMode */
@@ -3428,12 +3538,14 @@ export declare type KeysOfOtherType<TSchema, Type> = {
3428
3538
 
3429
3539
  /* Excluded from this release type: kOptions_3 */
3430
3540
 
3431
- /* Excluded from this release type: kParent */
3432
-
3433
3541
  /* Excluded from this release type: kPermits */
3434
3542
 
3543
+ /* Excluded from this release type: kPinnedConnection */
3544
+
3435
3545
  /* Excluded from this release type: kPipeline */
3436
3546
 
3547
+ /* Excluded from this release type: kProcessingWaitQueue */
3548
+
3437
3549
  /* Excluded from this release type: kQueue */
3438
3550
 
3439
3551
  /* Excluded from this release type: kResumeQueue */
@@ -3446,8 +3558,12 @@ export declare type KeysOfOtherType<TSchema, Type> = {
3446
3558
 
3447
3559
  /* Excluded from this release type: kServer_2 */
3448
3560
 
3561
+ /* Excluded from this release type: kServerError */
3562
+
3449
3563
  /* Excluded from this release type: kServerSession */
3450
3564
 
3565
+ /* Excluded from this release type: kServiceGenerations */
3566
+
3451
3567
  /* Excluded from this release type: kSession */
3452
3568
 
3453
3569
  /* Excluded from this release type: kSession_2 */
@@ -3473,7 +3589,7 @@ export declare const LEGAL_TCP_SOCKET_OPTIONS: readonly ["family", "hints", "loc
3473
3589
  export declare const LEGAL_TLS_SOCKET_OPTIONS: readonly ["ALPNProtocols", "ca", "cert", "checkServerIdentity", "ciphers", "crl", "ecdhCurve", "key", "minDHSize", "passphrase", "pfx", "rejectUnauthorized", "secureContext", "secureProtocol", "servername", "session"];
3474
3590
 
3475
3591
  /** @public */
3476
- export declare class ListCollectionsCursor<T extends Pick<CollectionInfo, 'name' | 'type'> | CollectionInfo = CollectionInfo> extends AbstractCursor<T> {
3592
+ export declare class ListCollectionsCursor<T extends Pick<CollectionInfo, 'name' | 'type'> | CollectionInfo = Pick<CollectionInfo, 'name' | 'type'> | CollectionInfo> extends AbstractCursor<T> {
3477
3593
  parent: Db;
3478
3594
  filter: Document;
3479
3595
  options?: ListCollectionsOptions;
@@ -3614,7 +3730,9 @@ export declare interface LoggerOptions {
3614
3730
  logger?: LoggerFunction;
3615
3731
  loggerLevel?: LoggerLevel;
3616
3732
  }
3733
+
3617
3734
  export { Long }
3735
+
3618
3736
  export { Map_2 as Map }
3619
3737
 
3620
3738
  /** @public */
@@ -3654,6 +3772,7 @@ export declare interface MapReduceOptions<TKey = ObjectId, TValue = Document> ex
3654
3772
 
3655
3773
  /** @public */
3656
3774
  export declare type MatchKeysAndValues<TSchema> = Readonly<Partial<TSchema>> & Record<string, any>;
3775
+
3657
3776
  export { MaxKey }
3658
3777
 
3659
3778
  /* Excluded from this release type: MessageStream */
@@ -3663,7 +3782,7 @@ export { MinKey }
3663
3782
 
3664
3783
  /** @public */
3665
3784
  export declare interface ModifyResult<TSchema = Document> {
3666
- value?: TSchema;
3785
+ value: TSchema | null;
3667
3786
  lastErrorObject?: Document;
3668
3787
  ok: 0 | 1;
3669
3788
  }
@@ -3671,6 +3790,32 @@ export declare interface ModifyResult<TSchema = Document> {
3671
3790
  /** @public */
3672
3791
  export declare const MONGO_CLIENT_EVENTS: readonly ["connectionPoolCreated", "connectionPoolClosed", "connectionCreated", "connectionReady", "connectionClosed", "connectionCheckOutStarted", "connectionCheckOutFailed", "connectionCheckedOut", "connectionCheckedIn", "connectionPoolCleared", ...("error" | "close" | "commandStarted" | "commandSucceeded" | "commandFailed" | "serverHeartbeatStarted" | "serverHeartbeatSucceeded" | "serverHeartbeatFailed" | "timeout" | "serverOpening" | "serverClosed" | "serverDescriptionChanged" | "topologyOpening" | "topologyClosed" | "topologyDescriptionChanged")[]];
3673
3792
 
3793
+ /**
3794
+ * An error generated when the driver API is used incorrectly
3795
+ *
3796
+ * @privateRemarks
3797
+ * Should **never** be directly instantiated
3798
+ *
3799
+ * @public
3800
+ * @category Error
3801
+ */
3802
+ export declare class MongoAPIError extends MongoDriverError {
3803
+ constructor(message: string);
3804
+ get name(): string;
3805
+ }
3806
+
3807
+ /**
3808
+ * An error generated when a batch command is reexecuted after one of the commands in the batch
3809
+ * has failed
3810
+ *
3811
+ * @public
3812
+ * @category Error
3813
+ */
3814
+ export declare class MongoBatchReExecutionError extends MongoAPIError {
3815
+ constructor(message?: string);
3816
+ get name(): string;
3817
+ }
3818
+
3674
3819
  /**
3675
3820
  * An error indicating an unsuccessful Bulk Write
3676
3821
  * @public
@@ -3678,8 +3823,14 @@ export declare const MONGO_CLIENT_EVENTS: readonly ["connectionPoolCreated", "co
3678
3823
  */
3679
3824
  export declare class MongoBulkWriteError extends MongoServerError {
3680
3825
  result: BulkWriteResult;
3826
+ writeErrors: OneOrMore<WriteError>;
3827
+ err?: WriteConcernError;
3681
3828
  /** Creates a new MongoBulkWriteError */
3682
- constructor(error: AnyError, result: BulkWriteResult);
3829
+ constructor(error: {
3830
+ message: string;
3831
+ code: number;
3832
+ writeErrors?: WriteError[];
3833
+ } | WriteConcernError | AnyError, result: BulkWriteResult);
3683
3834
  get name(): string;
3684
3835
  /** Number of documents inserted. */
3685
3836
  get insertedCount(): number;
@@ -3701,6 +3852,17 @@ export declare class MongoBulkWriteError extends MongoServerError {
3701
3852
  };
3702
3853
  }
3703
3854
 
3855
+ /**
3856
+ * An error generated when a ChangeStream operation fails to execute.
3857
+ *
3858
+ * @public
3859
+ * @category Error
3860
+ */
3861
+ export declare class MongoChangeStreamError extends MongoRuntimeError {
3862
+ constructor(message: string);
3863
+ get name(): string;
3864
+ }
3865
+
3704
3866
  /**
3705
3867
  * The **MongoClient** class is a class that allows for making Connections to MongoDB.
3706
3868
  * @public
@@ -3838,7 +4000,7 @@ export declare interface MongoClientOptions extends BSONSerializeOptions, Suppor
3838
4000
  ssl?: boolean;
3839
4001
  /** Specifies the location of a local TLS Certificate */
3840
4002
  tlsCertificateFile?: string;
3841
- /** Specifies the location of a local .pem file that contains either the clients TLS/SSL certificate or the clients TLS/SSL certificate and key. */
4003
+ /** Specifies the location of a local .pem file that contains either the client's TLS/SSL certificate and key or only the client's TLS/SSL key when tlsCertificateFile is used to provide the certificate. */
3842
4004
  tlsCertificateKeyFile?: string;
3843
4005
  /** Specifies the password to de-crypt the tlsCertificateKeyFile. */
3844
4006
  tlsCertificateKeyFilePassword?: string;
@@ -3854,8 +4016,8 @@ export declare interface MongoClientOptions extends BSONSerializeOptions, Suppor
3854
4016
  connectTimeoutMS?: number;
3855
4017
  /** The time in milliseconds to attempt a send or receive on a socket before the attempt times out. */
3856
4018
  socketTimeoutMS?: number;
3857
- /** Comma-delimited string of compressors to enable network compression for communication between this client and a mongod/mongos instance. */
3858
- compressors?: CompressorName[];
4019
+ /** An array or comma-delimited string of compressors to enable network compression for communication between this client and a mongod/mongos instance. */
4020
+ compressors?: CompressorName[] | string;
3859
4021
  /** An integer that specifies the compression level if using zlib for network compression. */
3860
4022
  zlibCompressionLevel?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | undefined;
3861
4023
  /** The maximum number of connections in the connection pool. */
@@ -3883,12 +4045,7 @@ export declare interface MongoClientOptions extends BSONSerializeOptions, Suppor
3883
4045
  /** Specify the authentication mechanism that MongoDB will use to authenticate the connection. */
3884
4046
  authMechanism?: AuthMechanism;
3885
4047
  /** Specify properties for the specified authMechanism as a comma-separated list of colon-separated key-value pairs. */
3886
- authMechanismProperties?: {
3887
- SERVICE_NAME?: string;
3888
- CANONICALIZE_HOST_NAME?: boolean;
3889
- SERVICE_REALM?: string;
3890
- [key: string]: any;
3891
- };
4048
+ authMechanismProperties?: AuthMechanismProperties;
3892
4049
  /** The size (in milliseconds) of the latency window for selecting among multiple suitable MongoDB instances. */
3893
4050
  localThresholdMS?: number;
3894
4051
  /** Specifies how long (in milliseconds) to block for server selection before throwing an exception. */
@@ -3905,6 +4062,8 @@ export declare interface MongoClientOptions extends BSONSerializeOptions, Suppor
3905
4062
  retryWrites?: boolean;
3906
4063
  /** Allow a driver to force a Single topology type with a connection string containing one host */
3907
4064
  directConnection?: boolean;
4065
+ /** Instruct the driver it is connecting to a load balancer fronting a mongos like service */
4066
+ loadBalanced?: boolean;
3908
4067
  /** The write concern w value */
3909
4068
  w?: W;
3910
4069
  /** The write concern timeout */
@@ -3969,6 +4128,19 @@ export declare interface MongoClientOptions extends BSONSerializeOptions, Suppor
3969
4128
 
3970
4129
  /* Excluded from this release type: MongoClientPrivate */
3971
4130
 
4131
+ /**
4132
+ * An error generated when a feature that is not enabled or allowed for the current server
4133
+ * configuration is used
4134
+ *
4135
+ *
4136
+ * @public
4137
+ * @category Error
4138
+ */
4139
+ export declare class MongoCompatibilityError extends MongoAPIError {
4140
+ constructor(message: string);
4141
+ get name(): string;
4142
+ }
4143
+
3972
4144
  /**
3973
4145
  * A representation of the credentials used by MongoDB
3974
4146
  * @public
@@ -3983,7 +4155,7 @@ export declare class MongoCredentials {
3983
4155
  /** The method used to authenticate */
3984
4156
  readonly mechanism: AuthMechanism;
3985
4157
  /** Special properties used by some types of auth mechanisms */
3986
- readonly mechanismProperties: Document;
4158
+ readonly mechanismProperties: AuthMechanismProperties;
3987
4159
  constructor(options: MongoCredentialsOptions);
3988
4160
  /** Determines if two MongoCredentials objects are equivalent */
3989
4161
  equals(other: MongoCredentials): boolean;
@@ -4005,7 +4177,30 @@ export declare interface MongoCredentialsOptions {
4005
4177
  source: string;
4006
4178
  db?: string;
4007
4179
  mechanism?: AuthMechanism;
4008
- mechanismProperties: Document;
4180
+ mechanismProperties: AuthMechanismProperties;
4181
+ }
4182
+
4183
+ /**
4184
+ * An error thrown when an attempt is made to read from a cursor that has been exhausted
4185
+ *
4186
+ * @public
4187
+ * @category Error
4188
+ */
4189
+ export declare class MongoCursorExhaustedError extends MongoAPIError {
4190
+ constructor(message?: string);
4191
+ get name(): string;
4192
+ }
4193
+
4194
+ /**
4195
+ * An error thrown when the user attempts to add options to a cursor that has already been
4196
+ * initialized
4197
+ *
4198
+ * @public
4199
+ * @category Error
4200
+ */
4201
+ export declare class MongoCursorInUseError extends MongoAPIError {
4202
+ constructor(message?: string);
4203
+ get name(): string;
4009
4204
  }
4010
4205
 
4011
4206
  /** @public */
@@ -4024,6 +4219,18 @@ export declare class MongoDBNamespace {
4024
4219
  static fromString(namespace?: string): MongoDBNamespace;
4025
4220
  }
4026
4221
 
4222
+ /**
4223
+ * An error generated when the driver fails to decompress
4224
+ * data received from the server.
4225
+ *
4226
+ * @public
4227
+ * @category Error
4228
+ */
4229
+ export declare class MongoDecompressionError extends MongoRuntimeError {
4230
+ constructor(message: string);
4231
+ get name(): string;
4232
+ }
4233
+
4027
4234
  /**
4028
4235
  * An error generated by the driver
4029
4236
  *
@@ -4031,7 +4238,6 @@ export declare class MongoDBNamespace {
4031
4238
  * @category Error
4032
4239
  */
4033
4240
  export declare class MongoDriverError extends MongoError {
4034
- code?: string;
4035
4241
  constructor(message: string);
4036
4242
  get name(): string;
4037
4243
  }
@@ -4045,6 +4251,11 @@ export declare class MongoDriverError extends MongoError {
4045
4251
  */
4046
4252
  export declare class MongoError extends Error {
4047
4253
  /* Excluded from this release type: [kErrorLabels] */
4254
+ /**
4255
+ * This is a number in MongoServerError and a string in MongoDriverError
4256
+ * @privateRemarks
4257
+ * Define the type override on the subclasses when we can use the override keyword
4258
+ */
4048
4259
  code?: number | string;
4049
4260
  topologyVersion?: TopologyVersion;
4050
4261
  constructor(message: string | Error);
@@ -4062,6 +4273,89 @@ export declare class MongoError extends Error {
4062
4273
  get errorLabels(): string[];
4063
4274
  }
4064
4275
 
4276
+ /**
4277
+ * An error generated when the user attempts to operate
4278
+ * on a session that has expired or has been closed.
4279
+ *
4280
+ * @public
4281
+ * @category Error
4282
+ */
4283
+ export declare class MongoExpiredSessionError extends MongoAPIError {
4284
+ constructor(message?: string);
4285
+ get name(): string;
4286
+ }
4287
+
4288
+ /**
4289
+ * An error generated when a malformed or invalid chunk is
4290
+ * encountered when reading from a GridFSStream.
4291
+ *
4292
+ * @public
4293
+ * @category Error
4294
+ */
4295
+ export declare class MongoGridFSChunkError extends MongoRuntimeError {
4296
+ constructor(message: string);
4297
+ get name(): string;
4298
+ }
4299
+
4300
+ /** An error generated when a GridFSStream operation fails to execute.
4301
+ *
4302
+ * @public
4303
+ * @category Error
4304
+ */
4305
+ export declare class MongoGridFSStreamError extends MongoRuntimeError {
4306
+ constructor(message: string);
4307
+ get name(): string;
4308
+ }
4309
+
4310
+ /**
4311
+ * An error generated when the user supplies malformed or unexpected arguments
4312
+ * or when a required argument or field is not provided.
4313
+ *
4314
+ *
4315
+ * @public
4316
+ * @category Error
4317
+ */
4318
+ export declare class MongoInvalidArgumentError extends MongoAPIError {
4319
+ constructor(message: string);
4320
+ get name(): string;
4321
+ }
4322
+
4323
+ /**
4324
+ * A error generated when the user attempts to authenticate
4325
+ * via Kerberos, but fails to connect to the Kerberos client.
4326
+ *
4327
+ * @public
4328
+ * @category Error
4329
+ */
4330
+ export declare class MongoKerberosError extends MongoRuntimeError {
4331
+ constructor(message: string);
4332
+ get name(): string;
4333
+ }
4334
+
4335
+ /**
4336
+ * An error generated when the user fails to provide authentication credentials before attempting
4337
+ * to connect to a mongo server instance.
4338
+ *
4339
+ *
4340
+ * @public
4341
+ * @category Error
4342
+ */
4343
+ export declare class MongoMissingCredentialsError extends MongoAPIError {
4344
+ constructor(message: string);
4345
+ get name(): string;
4346
+ }
4347
+
4348
+ /**
4349
+ * An error generated when a required module or dependency is not present in the local environment
4350
+ *
4351
+ * @public
4352
+ * @category Error
4353
+ */
4354
+ export declare class MongoMissingDependencyError extends MongoAPIError {
4355
+ constructor(message: string);
4356
+ get name(): string;
4357
+ }
4358
+
4065
4359
  /**
4066
4360
  * An error indicating an issue with the network, including TCP errors and timeouts.
4067
4361
  * @public
@@ -4069,12 +4363,16 @@ export declare class MongoError extends Error {
4069
4363
  */
4070
4364
  export declare class MongoNetworkError extends MongoError {
4071
4365
  /* Excluded from this release type: [kBeforeHandshake] */
4072
- constructor(message: string | Error, options?: {
4073
- beforeHandshake?: boolean;
4074
- });
4366
+ constructor(message: string | Error, options?: MongoNetworkErrorOptions);
4075
4367
  get name(): string;
4076
4368
  }
4077
4369
 
4370
+ /** @public */
4371
+ export declare interface MongoNetworkErrorOptions {
4372
+ /** Indicates the timeout happened before a connection handshake completed */
4373
+ beforeHandshake: boolean;
4374
+ }
4375
+
4078
4376
  /**
4079
4377
  * An error indicating a network timeout occurred
4080
4378
  * @public
@@ -4084,27 +4382,35 @@ export declare class MongoNetworkError extends MongoError {
4084
4382
  * CSFLE has a dependency on this error with an instanceof check
4085
4383
  */
4086
4384
  export declare class MongoNetworkTimeoutError extends MongoNetworkError {
4087
- constructor(message: string, options?: MongoNetworkTimeoutErrorOptions);
4385
+ constructor(message: string, options?: MongoNetworkErrorOptions);
4088
4386
  get name(): string;
4089
4387
  }
4090
4388
 
4091
- /** @public */
4092
- export declare interface MongoNetworkTimeoutErrorOptions {
4093
- /** Indicates the timeout happened before a connection handshake completed */
4094
- beforeHandshake: boolean;
4389
+ /**
4390
+ * An error thrown when the user attempts to operate on a database or collection through a MongoClient
4391
+ * that has not yet successfully called the "connect" method
4392
+ *
4393
+ * @public
4394
+ * @category Error
4395
+ */
4396
+ export declare class MongoNotConnectedError extends MongoAPIError {
4397
+ constructor(message: string);
4398
+ get name(): string;
4095
4399
  }
4096
4400
 
4097
4401
  /**
4098
4402
  * Mongo Client Options
4099
4403
  * @public
4100
4404
  */
4101
- export declare interface MongoOptions extends Required<Pick<MongoClientOptions, 'autoEncryption' | 'compressors' | 'connectTimeoutMS' | 'directConnection' | 'driverInfo' | 'forceServerObjectId' | 'minHeartbeatFrequencyMS' | 'heartbeatFrequencyMS' | 'keepAlive' | 'keepAliveInitialDelay' | 'localThresholdMS' | 'logger' | 'maxIdleTimeMS' | 'maxPoolSize' | 'minPoolSize' | 'monitorCommands' | 'noDelay' | 'pkFactory' | 'promiseLibrary' | 'raw' | 'replicaSet' | 'retryReads' | 'retryWrites' | 'serverSelectionTimeoutMS' | 'socketTimeoutMS' | 'tlsAllowInvalidCertificates' | 'tlsAllowInvalidHostnames' | 'tlsInsecure' | 'waitQueueTimeoutMS' | 'zlibCompressionLevel'>>, SupportedNodeConnectionOptions {
4405
+ export declare interface MongoOptions extends Required<Pick<MongoClientOptions, 'autoEncryption' | 'connectTimeoutMS' | 'directConnection' | 'driverInfo' | 'forceServerObjectId' | 'minHeartbeatFrequencyMS' | 'heartbeatFrequencyMS' | 'keepAlive' | 'keepAliveInitialDelay' | 'localThresholdMS' | 'logger' | 'maxIdleTimeMS' | 'maxPoolSize' | 'minPoolSize' | 'monitorCommands' | 'noDelay' | 'pkFactory' | 'promiseLibrary' | 'raw' | 'replicaSet' | 'retryReads' | 'retryWrites' | 'serverSelectionTimeoutMS' | 'socketTimeoutMS' | 'tlsAllowInvalidCertificates' | 'tlsAllowInvalidHostnames' | 'tlsInsecure' | 'waitQueueTimeoutMS' | 'zlibCompressionLevel'>>, SupportedNodeConnectionOptions {
4102
4406
  hosts: HostAddress[];
4103
4407
  srvHost?: string;
4104
4408
  credentials?: MongoCredentials;
4105
4409
  readPreference: ReadPreference;
4106
4410
  readConcern: ReadConcern;
4411
+ loadBalanced: boolean;
4107
4412
  serverApi: ServerApi;
4413
+ compressors: CompressorName[];
4108
4414
  writeConcern: WriteConcern;
4109
4415
  dbName: string;
4110
4416
  metadata: ClientMetadata;
@@ -4147,6 +4453,33 @@ export declare class MongoParseError extends MongoDriverError {
4147
4453
  get name(): string;
4148
4454
  }
4149
4455
 
4456
+ /**
4457
+ * An error generated when the driver encounters unexpected input
4458
+ * or reaches an unexpected/invalid internal state
4459
+ *
4460
+ * @privateRemarks
4461
+ * Should **never** be directly instantiated.
4462
+ *
4463
+ * @public
4464
+ * @category Error
4465
+ */
4466
+ export declare class MongoRuntimeError extends MongoDriverError {
4467
+ constructor(message: string);
4468
+ get name(): string;
4469
+ }
4470
+
4471
+ /**
4472
+ * An error generated when an attempt is made to operate
4473
+ * on a closed/closing server.
4474
+ *
4475
+ * @public
4476
+ * @category Error
4477
+ */
4478
+ export declare class MongoServerClosedError extends MongoAPIError {
4479
+ constructor(message?: string);
4480
+ get name(): string;
4481
+ }
4482
+
4150
4483
  /**
4151
4484
  * An error coming from the mongo server
4152
4485
  *
@@ -4154,10 +4487,12 @@ export declare class MongoParseError extends MongoDriverError {
4154
4487
  * @category Error
4155
4488
  */
4156
4489
  export declare class MongoServerError extends MongoError {
4157
- code?: number;
4158
4490
  codeName?: string;
4159
4491
  writeConcernError?: Document;
4160
- constructor(message: Error | ErrorDescription);
4492
+ errInfo?: Document;
4493
+ ok?: number;
4494
+ [key: string]: any;
4495
+ constructor(message: ErrorDescription);
4161
4496
  get name(): string;
4162
4497
  }
4163
4498
 
@@ -4183,6 +4518,30 @@ export declare class MongoSystemError extends MongoError {
4183
4518
  get name(): string;
4184
4519
  }
4185
4520
 
4521
+ /**
4522
+ * An error generated when an attempt is made to operate on a
4523
+ * dropped, or otherwise unavailable, database.
4524
+ *
4525
+ * @public
4526
+ * @category Error
4527
+ */
4528
+ export declare class MongoTopologyClosedError extends MongoAPIError {
4529
+ constructor(message?: string);
4530
+ get name(): string;
4531
+ }
4532
+
4533
+ /**
4534
+ * An error generated when the user makes a mistake in the usage of transactions.
4535
+ * (e.g. attempting to commit a transaction with a readPreference other than primary)
4536
+ *
4537
+ * @public
4538
+ * @category Error
4539
+ */
4540
+ export declare class MongoTransactionError extends MongoAPIError {
4541
+ constructor(message: string);
4542
+ get name(): string;
4543
+ }
4544
+
4186
4545
  /**
4187
4546
  * An error thrown when the server reports a writeConcernError
4188
4547
  * @public
@@ -4191,7 +4550,8 @@ export declare class MongoSystemError extends MongoError {
4191
4550
  export declare class MongoWriteConcernError extends MongoServerError {
4192
4551
  /** The result document (provided if ok: 1) */
4193
4552
  result?: Document;
4194
- constructor(message: ErrorDescription, result: Document);
4553
+ errInfo?: Document;
4554
+ constructor(message: ErrorDescription, result?: Document);
4195
4555
  get name(): string;
4196
4556
  }
4197
4557
 
@@ -4225,10 +4585,17 @@ export declare type NotAcceptedFields<TSchema, FieldType> = {
4225
4585
 
4226
4586
  /** @public */
4227
4587
  export declare type NumericType = IntegerType | Decimal128 | Double;
4588
+
4589
+ /**
4590
+ * @public
4591
+ * @deprecated Please use `ObjectId`
4592
+ */
4593
+ export declare const ObjectID: typeof ObjectId;
4594
+
4228
4595
  export { ObjectId }
4229
4596
 
4230
4597
  /** @public */
4231
- export declare type OneOrMore<T> = T | T[];
4598
+ export declare type OneOrMore<T> = T | ReadonlyArray<T>;
4232
4599
 
4233
4600
  /** @public */
4234
4601
  export declare type OnlyFieldsOfType<TSchema, FieldType = any, AssignableType = FieldType> = IsAny<TSchema[keyof TSchema], Record<string, FieldType>, AcceptedFields<TSchema, FieldType, AssignableType> & NotAcceptedFields<TSchema, FieldType> & Record<string, AssignableType>>;
@@ -4242,6 +4609,7 @@ export declare interface OperationOptions extends BSONSerializeOptions {
4242
4609
  willRetryWrites?: boolean;
4243
4610
  /** The preferred read preference (ReadPreference.primary, ReadPreference.primary_preferred, ReadPreference.secondary, ReadPreference.secondary_preferred, ReadPreference.nearest). */
4244
4611
  readPreference?: ReadPreferenceLike;
4612
+ /* Excluded from this release type: bypassPinningCheck */
4245
4613
  }
4246
4614
 
4247
4615
  /* Excluded from this release type: OperationParent */
@@ -4302,19 +4670,18 @@ export declare type ProfilingLevel = typeof ProfilingLevel[keyof typeof Profilin
4302
4670
  /** @public */
4303
4671
  export declare type ProfilingLevelOptions = CommandOperationOptions;
4304
4672
 
4305
- /** @public */
4306
- export declare type Projection<TSchema> = {
4307
- [Key in keyof TSchema]?: ProjectionOperators | 0 | 1 | boolean;
4308
- } & Partial<Record<string, ProjectionOperators | 0 | 1 | boolean>>;
4673
+ /**
4674
+ * @public
4675
+ * Projection is flexible to permit the wide array of aggregation operators
4676
+ * @deprecated since v4.1.0: Since projections support all aggregation operations we have no plans to narrow this type further
4677
+ */
4678
+ export declare type Projection<TSchema extends Document = Document> = Document;
4309
4679
 
4310
- /** @public */
4311
- export declare interface ProjectionOperators extends Document {
4312
- $elemMatch?: Document;
4313
- $slice?: number | [number, number];
4314
- $meta?: string;
4315
- /** @deprecated Since MongoDB 3.2, Use FindCursor#max */
4316
- $max?: any;
4317
- }
4680
+ /**
4681
+ * @public
4682
+ * @deprecated since v4.1.0: Since projections support all aggregation operations we have no plans to narrow this type further
4683
+ */
4684
+ export declare type ProjectionOperators = Document;
4318
4685
 
4319
4686
  /**
4320
4687
  * Global promise store allowing user-provided promises
@@ -4334,7 +4701,7 @@ export { Promise_2 as Promise }
4334
4701
  export declare type PullAllOperator<TSchema> = ({
4335
4702
  readonly [key in KeysOfAType<TSchema, ReadonlyArray<any>>]?: TSchema[key];
4336
4703
  } & NotAcceptedFields<TSchema, ReadonlyArray<any>>) & {
4337
- readonly [key: string]: any[];
4704
+ readonly [key: string]: ReadonlyArray<any>;
4338
4705
  };
4339
4706
 
4340
4707
  /** @public */
@@ -4855,6 +5222,7 @@ export declare const ServerType: Readonly<{
4855
5222
  readonly RSOther: "RSOther";
4856
5223
  readonly RSGhost: "RSGhost";
4857
5224
  readonly Unknown: "Unknown";
5225
+ readonly LoadBalancer: "LoadBalancer";
4858
5226
  }>;
4859
5227
 
4860
5228
  /** @public */
@@ -4909,6 +5277,7 @@ export declare class StreamDescription {
4909
5277
  compressors: CompressorName[];
4910
5278
  compressor?: CompressorName;
4911
5279
  logicalSessionTimeoutMinutes?: number;
5280
+ loadBalanced: boolean;
4912
5281
  __nodejs_mock_server__?: boolean;
4913
5282
  zlibCompressionLevel?: number;
4914
5283
  constructor(address: string, options?: StreamDescriptionOptions);
@@ -4918,6 +5287,8 @@ export declare class StreamDescription {
4918
5287
  /** @public */
4919
5288
  export declare interface StreamDescriptionOptions {
4920
5289
  compressors?: CompressorName[];
5290
+ logicalSessionTimeoutMinutes?: number;
5291
+ loadBalanced: boolean;
4921
5292
  }
4922
5293
 
4923
5294
  /** @public */
@@ -4948,6 +5319,7 @@ export declare interface TimeSeriesCollectionOptions extends Document {
4948
5319
  metaField?: string;
4949
5320
  granularity?: string;
4950
5321
  }
5322
+
4951
5323
  export { Timestamp }
4952
5324
 
4953
5325
  /* Excluded from this release type: Topology */
@@ -5058,6 +5430,7 @@ export declare interface TopologyOptions extends BSONSerializeOptions, ServerOpt
5058
5430
  /* Excluded from this release type: srvPoller */
5059
5431
  /** Indicates that a client should directly connect to a node without attempting to discover its topology type */
5060
5432
  directConnection: boolean;
5433
+ loadBalanced: boolean;
5061
5434
  metadata: ClientMetadata;
5062
5435
  /** MongoDB server API version */
5063
5436
  serverApi?: ServerApi;
@@ -5075,6 +5448,7 @@ export declare const TopologyType: Readonly<{
5075
5448
  readonly ReplicaSetWithPrimary: "ReplicaSetWithPrimary";
5076
5449
  readonly Sharded: "Sharded";
5077
5450
  readonly Unknown: "Unknown";
5451
+ readonly LoadBalanced: "LoadBalanced";
5078
5452
  }>;
5079
5453
 
5080
5454
  /** @public */
@@ -5105,6 +5479,7 @@ export declare class Transaction {
5105
5479
  * @returns Whether this session is presently in a transaction
5106
5480
  */
5107
5481
  get isActive(): boolean;
5482
+ get isCommitted(): boolean;
5108
5483
  /* Excluded from this release type: transition */
5109
5484
  /* Excluded from this release type: pinServer */
5110
5485
  /* Excluded from this release type: unpinServer */
@@ -5494,19 +5869,27 @@ export declare class WriteConcern {
5494
5869
  * @category Error
5495
5870
  */
5496
5871
  export declare class WriteConcernError {
5497
- err: MongoServerError;
5498
- constructor(err: MongoServerError);
5872
+ /* Excluded from this release type: [kServerError] */
5873
+ constructor(error: WriteConcernErrorData);
5499
5874
  /** Write concern error code. */
5500
5875
  get code(): number | undefined;
5501
5876
  /** Write concern error message. */
5502
- get errmsg(): string;
5503
- toJSON(): {
5504
- code?: number;
5505
- errmsg: string;
5506
- };
5877
+ get errmsg(): string | undefined;
5878
+ /** Write concern error info. */
5879
+ get errInfo(): Document | undefined;
5880
+ /** @deprecated The `err` prop that contained a MongoServerError has been deprecated. */
5881
+ get err(): WriteConcernErrorData;
5882
+ toJSON(): WriteConcernErrorData;
5507
5883
  toString(): string;
5508
5884
  }
5509
5885
 
5886
+ /** @public */
5887
+ export declare interface WriteConcernErrorData {
5888
+ code: number;
5889
+ errmsg: string;
5890
+ errInfo?: Document;
5891
+ }
5892
+
5510
5893
  /** @public */
5511
5894
  export declare interface WriteConcernOptions {
5512
5895
  /** Write Concern as an object */
@@ -5543,6 +5926,8 @@ export declare class WriteError {
5543
5926
  get index(): number;
5544
5927
  /** WriteError message. */
5545
5928
  get errmsg(): string | undefined;
5929
+ /** WriteError details. */
5930
+ get errInfo(): Document | undefined;
5546
5931
  /** Returns the underlying operation that caused the error */
5547
5932
  getOperation(): Document;
5548
5933
  toJSON(): {