mongodb 4.4.1 → 4.6.0

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 (204) hide show
  1. package/README.md +3 -2
  2. package/lib/admin.js +5 -6
  3. package/lib/admin.js.map +1 -1
  4. package/lib/bulk/common.js +34 -7
  5. package/lib/bulk/common.js.map +1 -1
  6. package/lib/bulk/unordered.js.map +1 -1
  7. package/lib/change_stream.js +251 -245
  8. package/lib/change_stream.js.map +1 -1
  9. package/lib/cmap/auth/gssapi.js.map +1 -1
  10. package/lib/cmap/auth/mongocr.js.map +1 -1
  11. package/lib/cmap/auth/mongodb_aws.js +3 -0
  12. package/lib/cmap/auth/mongodb_aws.js.map +1 -1
  13. package/lib/cmap/auth/plain.js.map +1 -1
  14. package/lib/cmap/auth/scram.js +1 -0
  15. package/lib/cmap/auth/scram.js.map +1 -1
  16. package/lib/cmap/auth/x509.js.map +1 -1
  17. package/lib/cmap/commands.js +12 -11
  18. package/lib/cmap/commands.js.map +1 -1
  19. package/lib/cmap/connect.js +8 -1
  20. package/lib/cmap/connect.js.map +1 -1
  21. package/lib/cmap/connection.js +111 -145
  22. package/lib/cmap/connection.js.map +1 -1
  23. package/lib/cmap/errors.js.map +1 -1
  24. package/lib/cmap/message_stream.js.map +1 -1
  25. package/lib/cmap/stream_description.js +3 -0
  26. package/lib/cmap/stream_description.js.map +1 -1
  27. package/lib/collection.js +60 -29
  28. package/lib/collection.js.map +1 -1
  29. package/lib/connection_string.js +32 -11
  30. package/lib/connection_string.js.map +1 -1
  31. package/lib/constants.js +8 -1
  32. package/lib/constants.js.map +1 -1
  33. package/lib/cursor/abstract_cursor.js +64 -51
  34. package/lib/cursor/abstract_cursor.js.map +1 -1
  35. package/lib/cursor/aggregation_cursor.js +2 -2
  36. package/lib/cursor/aggregation_cursor.js.map +1 -1
  37. package/lib/cursor/find_cursor.js +9 -4
  38. package/lib/cursor/find_cursor.js.map +1 -1
  39. package/lib/db.js +20 -13
  40. package/lib/db.js.map +1 -1
  41. package/lib/encrypter.js +21 -10
  42. package/lib/encrypter.js.map +1 -1
  43. package/lib/error.js +121 -59
  44. package/lib/error.js.map +1 -1
  45. package/lib/gridfs/download.js +2 -0
  46. package/lib/gridfs/download.js.map +1 -1
  47. package/lib/gridfs/index.js +42 -51
  48. package/lib/gridfs/index.js.map +1 -1
  49. package/lib/gridfs/upload.js +1 -1
  50. package/lib/gridfs/upload.js.map +1 -1
  51. package/lib/index.js +7 -3
  52. package/lib/index.js.map +1 -1
  53. package/lib/mongo_client.js +21 -27
  54. package/lib/mongo_client.js.map +1 -1
  55. package/lib/operations/add_user.js +8 -1
  56. package/lib/operations/add_user.js.map +1 -1
  57. package/lib/operations/aggregate.js +5 -0
  58. package/lib/operations/aggregate.js.map +1 -1
  59. package/lib/operations/bulk_write.js.map +1 -1
  60. package/lib/operations/collections.js.map +1 -1
  61. package/lib/operations/command.js +0 -3
  62. package/lib/operations/command.js.map +1 -1
  63. package/lib/operations/common_functions.js +8 -1
  64. package/lib/operations/common_functions.js.map +1 -1
  65. package/lib/operations/count.js.map +1 -1
  66. package/lib/operations/count_documents.js.map +1 -1
  67. package/lib/operations/create_collection.js +51 -17
  68. package/lib/operations/create_collection.js.map +1 -1
  69. package/lib/operations/delete.js +5 -3
  70. package/lib/operations/delete.js.map +1 -1
  71. package/lib/operations/distinct.js.map +1 -1
  72. package/lib/operations/drop.js +67 -7
  73. package/lib/operations/drop.js.map +1 -1
  74. package/lib/operations/estimated_document_count.js.map +1 -1
  75. package/lib/operations/eval.js.map +1 -1
  76. package/lib/operations/execute_operation.js +71 -79
  77. package/lib/operations/execute_operation.js.map +1 -1
  78. package/lib/operations/find.js +3 -52
  79. package/lib/operations/find.js.map +1 -1
  80. package/lib/operations/find_and_modify.js +5 -0
  81. package/lib/operations/find_and_modify.js.map +1 -1
  82. package/lib/operations/get_more.js +5 -0
  83. package/lib/operations/get_more.js.map +1 -1
  84. package/lib/operations/indexes.js +8 -9
  85. package/lib/operations/indexes.js.map +1 -1
  86. package/lib/operations/insert.js +8 -2
  87. package/lib/operations/insert.js.map +1 -1
  88. package/lib/operations/is_capped.js.map +1 -1
  89. package/lib/operations/list_collections.js +10 -42
  90. package/lib/operations/list_collections.js.map +1 -1
  91. package/lib/operations/list_databases.js +5 -0
  92. package/lib/operations/list_databases.js.map +1 -1
  93. package/lib/operations/map_reduce.js +1 -2
  94. package/lib/operations/map_reduce.js.map +1 -1
  95. package/lib/operations/operation.js +1 -3
  96. package/lib/operations/operation.js.map +1 -1
  97. package/lib/operations/options_operation.js.map +1 -1
  98. package/lib/operations/profiling_level.js.map +1 -1
  99. package/lib/operations/remove_user.js.map +1 -1
  100. package/lib/operations/rename.js +1 -1
  101. package/lib/operations/rename.js.map +1 -1
  102. package/lib/operations/run_command.js.map +1 -1
  103. package/lib/operations/set_profiling_level.js.map +1 -1
  104. package/lib/operations/stats.js.map +1 -1
  105. package/lib/operations/update.js +5 -0
  106. package/lib/operations/update.js.map +1 -1
  107. package/lib/operations/validate_collection.js.map +1 -1
  108. package/lib/read_concern.js +1 -0
  109. package/lib/read_concern.js.map +1 -1
  110. package/lib/sdam/common.js +1 -7
  111. package/lib/sdam/common.js.map +1 -1
  112. package/lib/sdam/events.js +1 -1
  113. package/lib/sdam/events.js.map +1 -1
  114. package/lib/sdam/monitor.js +1 -2
  115. package/lib/sdam/monitor.js.map +1 -1
  116. package/lib/sdam/server.js +108 -78
  117. package/lib/sdam/server.js.map +1 -1
  118. package/lib/sdam/topology.js +38 -55
  119. package/lib/sdam/topology.js.map +1 -1
  120. package/lib/sdam/topology_description.js +3 -4
  121. package/lib/sdam/topology_description.js.map +1 -1
  122. package/lib/sessions.js +93 -68
  123. package/lib/sessions.js.map +1 -1
  124. package/lib/utils.js +21 -97
  125. package/lib/utils.js.map +1 -1
  126. package/mongodb.d.ts +417 -92
  127. package/package.json +25 -29
  128. package/src/admin.ts +6 -10
  129. package/src/bulk/common.ts +45 -14
  130. package/src/bulk/unordered.ts +1 -1
  131. package/src/change_stream.ts +559 -425
  132. package/src/cmap/auth/gssapi.ts +1 -1
  133. package/src/cmap/auth/mongocr.ts +1 -1
  134. package/src/cmap/auth/mongodb_aws.ts +6 -1
  135. package/src/cmap/auth/plain.ts +1 -1
  136. package/src/cmap/auth/scram.ts +3 -2
  137. package/src/cmap/auth/x509.ts +6 -2
  138. package/src/cmap/commands.ts +26 -22
  139. package/src/cmap/connect.ts +15 -14
  140. package/src/cmap/connection.ts +163 -185
  141. package/src/cmap/errors.ts +2 -2
  142. package/src/cmap/message_stream.ts +2 -2
  143. package/src/cmap/stream_description.ts +4 -1
  144. package/src/collection.ts +66 -35
  145. package/src/connection_string.ts +46 -18
  146. package/src/constants.ts +6 -0
  147. package/src/cursor/abstract_cursor.ts +87 -65
  148. package/src/cursor/aggregation_cursor.ts +4 -4
  149. package/src/cursor/find_cursor.ts +16 -8
  150. package/src/db.ts +27 -24
  151. package/src/deps.ts +40 -0
  152. package/src/encrypter.ts +22 -11
  153. package/src/error.ts +170 -89
  154. package/src/gridfs/download.ts +3 -1
  155. package/src/gridfs/index.ts +51 -68
  156. package/src/gridfs/upload.ts +13 -13
  157. package/src/index.ts +21 -0
  158. package/src/mongo_client.ts +36 -50
  159. package/src/mongo_types.ts +1 -1
  160. package/src/operations/add_user.ts +14 -3
  161. package/src/operations/aggregate.ts +15 -5
  162. package/src/operations/bulk_write.ts +6 -2
  163. package/src/operations/collections.ts +6 -2
  164. package/src/operations/command.ts +23 -12
  165. package/src/operations/common_functions.ts +8 -1
  166. package/src/operations/count.ts +6 -2
  167. package/src/operations/count_documents.ts +5 -1
  168. package/src/operations/create_collection.ts +91 -23
  169. package/src/operations/delete.ts +19 -13
  170. package/src/operations/distinct.ts +6 -2
  171. package/src/operations/drop.ts +100 -10
  172. package/src/operations/estimated_document_count.ts +11 -3
  173. package/src/operations/eval.ts +6 -2
  174. package/src/operations/execute_operation.ts +103 -101
  175. package/src/operations/find.ts +9 -85
  176. package/src/operations/find_and_modify.ts +21 -2
  177. package/src/operations/get_more.ts +20 -6
  178. package/src/operations/indexes.ts +54 -36
  179. package/src/operations/insert.ts +28 -7
  180. package/src/operations/is_capped.ts +6 -2
  181. package/src/operations/list_collections.ts +24 -59
  182. package/src/operations/list_databases.ts +13 -3
  183. package/src/operations/map_reduce.ts +7 -6
  184. package/src/operations/operation.ts +10 -9
  185. package/src/operations/options_operation.ts +6 -2
  186. package/src/operations/profiling_level.ts +6 -2
  187. package/src/operations/remove_user.ts +6 -2
  188. package/src/operations/rename.ts +7 -3
  189. package/src/operations/run_command.ts +6 -2
  190. package/src/operations/set_profiling_level.ts +6 -2
  191. package/src/operations/stats.ts +12 -4
  192. package/src/operations/update.ts +19 -9
  193. package/src/operations/validate_collection.ts +6 -2
  194. package/src/read_concern.ts +1 -0
  195. package/src/sdam/common.ts +0 -6
  196. package/src/sdam/events.ts +2 -2
  197. package/src/sdam/monitor.ts +4 -5
  198. package/src/sdam/server.ts +125 -117
  199. package/src/sdam/topology.ts +39 -78
  200. package/src/sdam/topology_description.ts +3 -4
  201. package/src/sessions.ts +108 -78
  202. package/src/utils.ts +39 -119
  203. package/tsconfig.json +40 -0
  204. package/mongodb.ts34.d.ts +0 -5720
package/mongodb.d.ts CHANGED
@@ -67,7 +67,7 @@ export declare abstract class AbstractCursor<TSchema = any, CursorEvents extends
67
67
  /** Returns current buffered documents */
68
68
  readBufferedDocuments(number?: number): TSchema[];
69
69
  [Symbol.asyncIterator](): AsyncIterator<TSchema, void>;
70
- stream(options?: CursorStreamOptions): Readable;
70
+ stream(options?: CursorStreamOptions): Readable & AsyncIterable<TSchema>;
71
71
  hasNext(): Promise<boolean>;
72
72
  hasNext(callback: Callback<boolean>): void;
73
73
  /** Get the next available document from the cursor, returns null if no more documents are available. */
@@ -87,7 +87,7 @@ export declare abstract class AbstractCursor<TSchema = any, CursorEvents extends
87
87
  */
88
88
  forEach(iterator: (doc: TSchema) => boolean | void): Promise<void>;
89
89
  forEach(iterator: (doc: TSchema) => boolean | void, callback: Callback<void>): void;
90
- close(): void;
90
+ close(): Promise<void>;
91
91
  close(callback: Callback): void;
92
92
  /**
93
93
  * @deprecated options argument is deprecated
@@ -170,6 +170,7 @@ export declare abstract class AbstractCursor<TSchema = any, CursorEvents extends
170
170
  abstract clone(): AbstractCursor<TSchema>;
171
171
  /* Excluded from this release type: _initialize */
172
172
  /* Excluded from this release type: _getMore */
173
+ /* Excluded from this release type: [kInit] */
173
174
  }
174
175
 
175
176
  /** @public */
@@ -184,7 +185,15 @@ export declare interface AbstractCursorOptions extends BSONSerializeOptions {
184
185
  readConcern?: ReadConcernLike;
185
186
  batchSize?: number;
186
187
  maxTimeMS?: number;
187
- comment?: Document | string;
188
+ /**
189
+ * Comment to apply to the operation.
190
+ *
191
+ * In server versions pre-4.4, 'comment' must be string. A server
192
+ * error will be thrown if any other type is provided.
193
+ *
194
+ * In server versions 4.4 and above, 'comment' can be any valid BSON type.
195
+ */
196
+ comment?: unknown;
188
197
  tailable?: boolean;
189
198
  awaitData?: boolean;
190
199
  noCursorTimeout?: boolean;
@@ -390,7 +399,7 @@ export declare interface AggregateOptions extends CommandOperationOptions {
390
399
  * or higher stream
391
400
  * @public
392
401
  */
393
- export declare class AggregationCursor<TSchema = Document> extends AbstractCursor<TSchema> {
402
+ export declare class AggregationCursor<TSchema = any> extends AbstractCursor<TSchema> {
394
403
  /* Excluded from this release type: [kPipeline] */
395
404
  /* Excluded from this release type: [kOptions] */
396
405
  /* Excluded from this release type: __constructor */
@@ -546,6 +555,10 @@ export declare interface AutoEncrypter {
546
555
  teardown(force: boolean, callback: Callback): void;
547
556
  encrypt(ns: string, cmd: Document, options: any, callback: Callback<Document>): void;
548
557
  decrypt(cmd: Document, options: any, callback: Callback<Document>): void;
558
+ readonly csfleVersionInfo: {
559
+ version: bigint;
560
+ versionStr: string;
561
+ } | null;
549
562
  }
550
563
 
551
564
  /** @public */
@@ -639,8 +652,12 @@ export declare interface AutoEncryptionOptions {
639
652
  * Other validation rules in the JSON schema will not be enforced by the driver and will result in an error.
640
653
  */
641
654
  schemaMap?: Document;
655
+ /** @experimental */
656
+ encryptedFieldsMap?: Document;
642
657
  /** Allows the user to bypass auto encryption, maintaining implicit decryption */
643
658
  bypassAutoEncryption?: boolean;
659
+ /** @experimental */
660
+ bypassQueryAnalysis?: boolean;
644
661
  options?: {
645
662
  /** An optional hook to catch logging messages from the underlying encryption engine */
646
663
  logger?: (level: AutoEncryptionLoggerLevel, message: string) => void;
@@ -657,6 +674,36 @@ export declare interface AutoEncryptionOptions {
657
674
  mongocryptdSpawnPath?: string;
658
675
  /** Command line arguments to use when auto-spawning a mongocryptd */
659
676
  mongocryptdSpawnArgs?: string[];
677
+ /**
678
+ * Full path to a CSFLE shared library to be used (instead of mongocryptd).
679
+ *
680
+ * This needs to be the path to the file itself, not a directory.
681
+ * It can be an absolute or relative path. If the path is relative and
682
+ * its first component is `$ORIGIN`, it will be replaced by the directory
683
+ * containing the mongodb-client-encryption native addon file. Otherwise,
684
+ * the path will be interpreted relative to the current working directory.
685
+ *
686
+ * Currently, loading different CSFLE shared library files from different
687
+ * MongoClients in the same process is not supported.
688
+ *
689
+ * If this option is provided and no CSFLE shared library could be loaded
690
+ * from the specified location, creating the MongoClient will fail.
691
+ *
692
+ * If this option is not provided and `csfleRequired` is not specified,
693
+ * the AutoEncrypter will attempt to spawn and/or use mongocryptd according
694
+ * to the mongocryptd-specific `extraOptions` options.
695
+ *
696
+ * Specifying a path prevents mongocryptd from being used as a fallback.
697
+ */
698
+ csflePath?: string;
699
+ /**
700
+ * If specified, never use mongocryptd and instead fail when the CSFLE shared library
701
+ * could not be loaded.
702
+ *
703
+ * This is always true when `csflePath` is specified.
704
+ */
705
+ csfleRequired?: boolean;
706
+ /* Excluded from this release type: csfleSearchPaths */
660
707
  };
661
708
  proxyOptions?: ProxyOptions;
662
709
  /** The TLS options to use connecting to the KMS provider */
@@ -720,6 +767,8 @@ export declare type BatchType = typeof BatchType[keyof typeof BatchType];
720
767
 
721
768
  export { Binary }
722
769
 
770
+ /* Excluded from this release type: BinMsg */
771
+
723
772
  /** @public */
724
773
  export declare type BitwiseFilter = number /** numeric bit mask */ | Binary /** BinData bit mask */ | ReadonlyArray<number>;
725
774
 
@@ -878,6 +927,8 @@ export declare interface BulkWriteOptions extends CommandOperationOptions {
878
927
  keepGoing?: boolean;
879
928
  /** Force server to assign _id values instead of driver. */
880
929
  forceServerObjectId?: boolean;
930
+ /** Map of parameter names and values that can be accessed using $$var (requires MongoDB 5.0). */
931
+ let?: Document;
881
932
  }
882
933
 
883
934
  /**
@@ -958,7 +1009,7 @@ export declare class CancellationToken extends TypedEventEmitter<{
958
1009
  * Creates a new Change Stream instance. Normally created using {@link Collection#watch|Collection.watch()}.
959
1010
  * @public
960
1011
  */
961
- export declare class ChangeStream<TSchema extends Document = Document> extends TypedEventEmitter<ChangeStreamEvents<TSchema>> {
1012
+ export declare class ChangeStream<TSchema extends Document = Document, TChange extends Document = ChangeStreamDocument<TSchema>> extends TypedEventEmitter<ChangeStreamEvents<TSchema, TChange>> {
962
1013
  pipeline: Document[];
963
1014
  options: ChangeStreamOptions;
964
1015
  parent: MongoClient | Db | Collection;
@@ -1002,8 +1053,8 @@ export declare class ChangeStream<TSchema extends Document = Document> extends T
1002
1053
  hasNext(): Promise<boolean>;
1003
1054
  hasNext(callback: Callback<boolean>): void;
1004
1055
  /** Get the next available document from the Change Stream. */
1005
- next(): Promise<ChangeStreamDocument<TSchema>>;
1006
- next(callback: Callback<ChangeStreamDocument<TSchema>>): void;
1056
+ next(): Promise<TChange>;
1057
+ next(callback: Callback<TChange>): void;
1007
1058
  /** Is the cursor closed */
1008
1059
  get closed(): boolean;
1009
1060
  /** Close the Change Stream */
@@ -1012,102 +1063,231 @@ export declare class ChangeStream<TSchema extends Document = Document> extends T
1012
1063
  * Return a modified Readable stream including a possible transform method.
1013
1064
  * @throws MongoDriverError if this.cursor is undefined
1014
1065
  */
1015
- stream(options?: CursorStreamOptions): Readable;
1066
+ stream(options?: CursorStreamOptions): Readable & AsyncIterable<TChange>;
1016
1067
  /**
1017
1068
  * Try to get the next available document from the Change Stream's cursor or `null` if an empty batch is returned
1018
1069
  */
1019
1070
  tryNext(): Promise<Document | null>;
1020
1071
  tryNext(callback: Callback<Document | null>): void;
1072
+ /* Excluded from this release type: _setIsEmitter */
1073
+ /* Excluded from this release type: _setIsIterator */
1074
+ /* Excluded from this release type: _createChangeStreamCursor */
1075
+ /* Excluded from this release type: _waitForTopologyConnected */
1076
+ /* Excluded from this release type: _closeWithError */
1077
+ /* Excluded from this release type: _streamEvents */
1078
+ /* Excluded from this release type: _endStream */
1079
+ /* Excluded from this release type: _processNewChange */
1080
+ /* Excluded from this release type: _processError */
1081
+ /* Excluded from this release type: _getCursor */
1082
+ /* Excluded from this release type: _processResumeQueue */
1021
1083
  }
1022
1084
 
1085
+ /* Excluded from this release type: ChangeStreamAggregateRawResult */
1086
+
1023
1087
  /* Excluded from this release type: ChangeStreamCursor */
1024
1088
 
1025
1089
  /* Excluded from this release type: ChangeStreamCursorOptions */
1026
1090
 
1091
+ /**
1092
+ * @public
1093
+ * @see https://www.mongodb.com/docs/manual/reference/change-events/#delete-event
1094
+ */
1095
+ export declare interface ChangeStreamDeleteDocument<TSchema extends Document = Document> extends ChangeStreamDocumentCommon, ChangeStreamDocumentKey<TSchema> {
1096
+ /** Describes the type of operation represented in this change notification */
1097
+ operationType: 'delete';
1098
+ /** Namespace the delete event occured on */
1099
+ ns: ChangeStreamNameSpace;
1100
+ }
1101
+
1102
+ /** @public */
1103
+ export declare type ChangeStreamDocument<TSchema extends Document = Document> = ChangeStreamInsertDocument<TSchema> | ChangeStreamUpdateDocument<TSchema> | ChangeStreamReplaceDocument<TSchema> | ChangeStreamDeleteDocument<TSchema> | ChangeStreamDropDocument | ChangeStreamRenameDocument | ChangeStreamDropDatabaseDocument | ChangeStreamInvalidateDocument;
1104
+
1027
1105
  /** @public */
1028
- export declare interface ChangeStreamDocument<TSchema extends Document = Document> {
1106
+ export declare interface ChangeStreamDocumentCommon {
1029
1107
  /**
1030
1108
  * The id functions as an opaque token for use when resuming an interrupted
1031
1109
  * change stream.
1032
1110
  */
1033
- _id: InferIdType<TSchema>;
1034
- /**
1035
- * Describes the type of operation represented in this change notification.
1036
- */
1037
- operationType: 'insert' | 'update' | 'replace' | 'delete' | 'invalidate' | 'drop' | 'dropDatabase' | 'rename';
1111
+ _id: ResumeToken;
1038
1112
  /**
1039
- * Contains two fields: “db” and “coll” containing the database and
1040
- * collection name in which the change happened.
1113
+ * The timestamp from the oplog entry associated with the event.
1114
+ * For events that happened as part of a multi-document transaction, the associated change stream
1115
+ * notifications will have the same clusterTime value, namely the time when the transaction was committed.
1116
+ * On a sharded cluster, events that occur on different shards can have the same clusterTime but be
1117
+ * associated with different transactions or even not be associated with any transaction.
1118
+ * To identify events for a single transaction, you can use the combination of lsid and txnNumber in the change stream event document.
1041
1119
  */
1042
- ns: {
1043
- db: string;
1044
- coll: string;
1045
- };
1120
+ clusterTime?: Timestamp;
1046
1121
  /**
1047
- * Only present for ops of type ‘insert’, ‘update’, ‘replace’, and
1048
- * ‘delete’.
1122
+ * The transaction number.
1123
+ * Only present if the operation is part of a multi-document transaction.
1049
1124
  *
1050
- * For unsharded collections this contains a single field, _id, with the
1051
- * value of the _id of the document updated. For sharded collections,
1052
- * this will contain all the components of the shard key in order,
1053
- * followed by the _id if the _id isn’t part of the shard key.
1125
+ * **NOTE:** txnNumber can be a Long if promoteLongs is set to false
1054
1126
  */
1055
- documentKey?: {
1056
- _id: InferIdType<TSchema>;
1057
- };
1127
+ txnNumber?: number;
1058
1128
  /**
1059
- * Only present for ops of type ‘update’.
1060
- *
1061
- * Contains a description of updated and removed fields in this
1062
- * operation.
1129
+ * The identifier for the session associated with the transaction.
1130
+ * Only present if the operation is part of a multi-document transaction.
1063
1131
  */
1064
- updateDescription?: UpdateDescription<TSchema>;
1132
+ lsid?: ServerSessionId;
1133
+ }
1134
+
1135
+ /** @public */
1136
+ export declare interface ChangeStreamDocumentKey<TSchema extends Document = Document> {
1065
1137
  /**
1066
- * Always present for operations of type ‘insert’ and ‘replace’. Also
1067
- * present for operations of type ‘update’ if the user has specified ‘updateLookup’
1068
- * in the ‘fullDocument’ arguments to the ‘$changeStream’ stage.
1069
- *
1070
- * For operations of type ‘insert’ and ‘replace’, this key will contain the
1071
- * document being inserted, or the new version of the document that is replacing
1072
- * the existing document, respectively.
1073
- *
1074
- * For operations of type ‘update’, this key will contain a copy of the full
1075
- * version of the document from some point after the update occurred. If the
1076
- * document was deleted since the updated happened, it will be null.
1138
+ * For unsharded collections this contains a single field `_id`.
1139
+ * For sharded collections, this will contain all the components of the shard key
1077
1140
  */
1078
- fullDocument?: TSchema;
1141
+ documentKey: {
1142
+ _id: InferIdType<TSchema>;
1143
+ [shardKey: string]: any;
1144
+ };
1145
+ }
1146
+
1147
+ /**
1148
+ * @public
1149
+ * @see https://www.mongodb.com/docs/manual/reference/change-events/#dropdatabase-event
1150
+ */
1151
+ export declare interface ChangeStreamDropDatabaseDocument extends ChangeStreamDocumentCommon {
1152
+ /** Describes the type of operation represented in this change notification */
1153
+ operationType: 'dropDatabase';
1154
+ /** The database dropped */
1155
+ ns: {
1156
+ db: string;
1157
+ };
1158
+ }
1159
+
1160
+ /**
1161
+ * @public
1162
+ * @see https://www.mongodb.com/docs/manual/reference/change-events/#drop-event
1163
+ */
1164
+ export declare interface ChangeStreamDropDocument extends ChangeStreamDocumentCommon {
1165
+ /** Describes the type of operation represented in this change notification */
1166
+ operationType: 'drop';
1167
+ /** Namespace the drop event occured on */
1168
+ ns: ChangeStreamNameSpace;
1079
1169
  }
1080
1170
 
1081
1171
  /** @public */
1082
- export declare type ChangeStreamEvents<TSchema extends Document = Document> = {
1172
+ export declare type ChangeStreamEvents<TSchema extends Document = Document, TChange extends Document = ChangeStreamDocument<TSchema>> = {
1083
1173
  resumeTokenChanged(token: ResumeToken): void;
1084
- init(response: TSchema): void;
1085
- more(response?: TSchema | undefined): void;
1174
+ init(response: any): void;
1175
+ more(response?: any): void;
1086
1176
  response(): void;
1087
1177
  end(): void;
1088
1178
  error(error: Error): void;
1089
- change(change: ChangeStreamDocument<TSchema>): void;
1179
+ change(change: TChange): void;
1090
1180
  } & AbstractCursorEvents;
1091
1181
 
1182
+ /**
1183
+ * @public
1184
+ * @see https://www.mongodb.com/docs/manual/reference/change-events/#insert-event
1185
+ */
1186
+ export declare interface ChangeStreamInsertDocument<TSchema extends Document = Document> extends ChangeStreamDocumentCommon, ChangeStreamDocumentKey<TSchema> {
1187
+ /** Describes the type of operation represented in this change notification */
1188
+ operationType: 'insert';
1189
+ /** This key will contain the document being inserted */
1190
+ fullDocument: TSchema;
1191
+ /** Namespace the insert event occured on */
1192
+ ns: ChangeStreamNameSpace;
1193
+ }
1194
+
1195
+ /**
1196
+ * @public
1197
+ * @see https://www.mongodb.com/docs/manual/reference/change-events/#invalidate-event
1198
+ */
1199
+ export declare interface ChangeStreamInvalidateDocument extends ChangeStreamDocumentCommon {
1200
+ /** Describes the type of operation represented in this change notification */
1201
+ operationType: 'invalidate';
1202
+ }
1203
+
1204
+ /** @public */
1205
+ export declare interface ChangeStreamNameSpace {
1206
+ db: string;
1207
+ coll: string;
1208
+ }
1209
+
1092
1210
  /**
1093
1211
  * Options that can be passed to a ChangeStream. Note that startAfter, resumeAfter, and startAtOperationTime are all mutually exclusive, and the server will error if more than one is specified.
1094
1212
  * @public
1095
1213
  */
1096
1214
  export declare interface ChangeStreamOptions extends AggregateOptions {
1097
- /** Allowed values: ‘default’, ‘updateLookup’. When set to ‘updateLookup’, the change stream will include both a delta describing the changes to the document, as well as a copy of the entire document that was changed from some time after the change occurred. */
1215
+ /**
1216
+ * Allowed values: 'updateLookup'. When set to 'updateLookup',
1217
+ * the change stream will include both a delta describing the changes to the document,
1218
+ * as well as a copy of the entire document that was changed from some time after the change occurred.
1219
+ */
1098
1220
  fullDocument?: string;
1099
1221
  /** The maximum amount of time for the server to wait on new documents to satisfy a change stream query. */
1100
1222
  maxAwaitTimeMS?: number;
1101
- /** Allows you to start a changeStream after a specified event. See {@link https://docs.mongodb.com/manual/changeStreams/#resumeafter-for-change-streams|ChangeStream documentation}. */
1223
+ /**
1224
+ * Allows you to start a changeStream after a specified event.
1225
+ * @see https://docs.mongodb.com/manual/changeStreams/#resumeafter-for-change-streams
1226
+ */
1102
1227
  resumeAfter?: ResumeToken;
1103
- /** Similar to resumeAfter, but will allow you to start after an invalidated event. See {@link https://docs.mongodb.com/manual/changeStreams/#startafter-for-change-streams|ChangeStream documentation}. */
1228
+ /**
1229
+ * Similar to resumeAfter, but will allow you to start after an invalidated event.
1230
+ * @see https://docs.mongodb.com/manual/changeStreams/#startafter-for-change-streams
1231
+ */
1104
1232
  startAfter?: ResumeToken;
1105
1233
  /** Will start the changeStream after the specified operationTime. */
1106
1234
  startAtOperationTime?: OperationTime;
1107
- /** The number of documents to return per batch. See {@link https://docs.mongodb.com/manual/reference/command/aggregate|aggregation documentation}. */
1235
+ /**
1236
+ * The number of documents to return per batch.
1237
+ * @see https://docs.mongodb.com/manual/reference/command/aggregate
1238
+ */
1108
1239
  batchSize?: number;
1109
1240
  }
1110
1241
 
1242
+ /**
1243
+ * @public
1244
+ * @see https://www.mongodb.com/docs/manual/reference/change-events/#rename-event
1245
+ */
1246
+ export declare interface ChangeStreamRenameDocument extends ChangeStreamDocumentCommon {
1247
+ /** Describes the type of operation represented in this change notification */
1248
+ operationType: 'rename';
1249
+ /** The new name for the `ns.coll` collection */
1250
+ to: {
1251
+ db: string;
1252
+ coll: string;
1253
+ };
1254
+ /** The "from" namespace that the rename occured on */
1255
+ ns: ChangeStreamNameSpace;
1256
+ }
1257
+
1258
+ /**
1259
+ * @public
1260
+ * @see https://www.mongodb.com/docs/manual/reference/change-events/#replace-event
1261
+ */
1262
+ export declare interface ChangeStreamReplaceDocument<TSchema extends Document = Document> extends ChangeStreamDocumentCommon, ChangeStreamDocumentKey<TSchema> {
1263
+ /** Describes the type of operation represented in this change notification */
1264
+ operationType: 'replace';
1265
+ /** The fullDocument of a replace event represents the document after the insert of the replacement document */
1266
+ fullDocument: TSchema;
1267
+ /** Namespace the replace event occured on */
1268
+ ns: ChangeStreamNameSpace;
1269
+ }
1270
+
1271
+ /**
1272
+ * @public
1273
+ * @see https://www.mongodb.com/docs/manual/reference/change-events/#update-event
1274
+ */
1275
+ export declare interface ChangeStreamUpdateDocument<TSchema extends Document = Document> extends ChangeStreamDocumentCommon, ChangeStreamDocumentKey<TSchema> {
1276
+ /** Describes the type of operation represented in this change notification */
1277
+ operationType: 'update';
1278
+ /**
1279
+ * This is only set if `fullDocument` is set to `'updateLookup'`
1280
+ * The fullDocument document represents the most current majority-committed version of the updated document.
1281
+ * The fullDocument document may vary from the document at the time of the update operation depending on the
1282
+ * number of interleaving majority-committed operations that occur between the update operation and the document lookup.
1283
+ */
1284
+ fullDocument?: TSchema;
1285
+ /** Contains a description of updated and removed fields in this operation */
1286
+ updateDescription: UpdateDescription<TSchema>;
1287
+ /** Namespace the update event occured on */
1288
+ ns: ChangeStreamNameSpace;
1289
+ }
1290
+
1111
1291
  /** @public */
1112
1292
  export declare interface ClientMetadata {
1113
1293
  driver: {
@@ -1161,6 +1341,7 @@ export declare class ClientSession extends TypedEventEmitter<ClientSessionEvents
1161
1341
  /* Excluded from this release type: [kSnapshotTime] */
1162
1342
  /* Excluded from this release type: [kSnapshotEnabled] */
1163
1343
  /* Excluded from this release type: [kPinnedConnection] */
1344
+ /* Excluded from this release type: [kTxnNumberIncrement] */
1164
1345
  /* Excluded from this release type: __constructor */
1165
1346
  /** The server id associated with this session */
1166
1347
  get id(): ServerSessionId | undefined;
@@ -1200,7 +1381,14 @@ export declare class ClientSession extends TypedEventEmitter<ClientSessionEvents
1200
1381
  * @param session - The session to compare to
1201
1382
  */
1202
1383
  equals(session: ClientSession): boolean;
1203
- /** Increment the transaction number on the internal ServerSession */
1384
+ /**
1385
+ * Increment the transaction number on the internal ServerSession
1386
+ *
1387
+ * @privateRemarks
1388
+ * This helper increments a value stored on the client session that will be
1389
+ * added to the serverSession's txnNumber upon applying it to a command.
1390
+ * This is because the serverSession is lazily acquired after a connection is obtained
1391
+ */
1204
1392
  incrementTransactionNumber(): void;
1205
1393
  /** @returns whether this session is currently in a transaction or not */
1206
1394
  inTransaction(): boolean;
@@ -1265,6 +1453,17 @@ export declare interface CloseOptions {
1265
1453
  force?: boolean;
1266
1454
  }
1267
1455
 
1456
+ /** @public
1457
+ * Configuration options for clustered collections
1458
+ * TODO: NODE-4230 replace with normal manual link once it is on there.
1459
+ * @see https://www.mongodb.com/docs/v5.3/core/clustered-collections/
1460
+ */
1461
+ export declare interface ClusteredCollectionOptions extends Document {
1462
+ name?: string;
1463
+ key: Document;
1464
+ unique: boolean;
1465
+ }
1466
+
1268
1467
  /** @public */
1269
1468
  export declare interface ClusterTime {
1270
1469
  clusterTime: Timestamp;
@@ -1519,7 +1718,7 @@ export declare class Collection<TSchema extends Document = Document> {
1519
1718
  */
1520
1719
  find(): FindCursor<WithId<TSchema>>;
1521
1720
  find(filter: Filter<TSchema>, options?: FindOptions): FindCursor<WithId<TSchema>>;
1522
- find<T>(filter: Filter<TSchema>, options?: FindOptions): FindCursor<T>;
1721
+ find<T extends Document>(filter: Filter<TSchema>, options?: FindOptions): FindCursor<T>;
1523
1722
  /**
1524
1723
  * Returns the options of the collection.
1525
1724
  *
@@ -1781,15 +1980,46 @@ export declare class Collection<TSchema extends Document = Document> {
1781
1980
  * @param pipeline - An array of aggregation pipelines to execute
1782
1981
  * @param options - Optional settings for the command
1783
1982
  */
1784
- aggregate<T = Document>(pipeline?: Document[], options?: AggregateOptions): AggregationCursor<T>;
1983
+ aggregate<T extends Document = Document>(pipeline?: Document[], options?: AggregateOptions): AggregationCursor<T>;
1785
1984
  /**
1786
1985
  * Create a new Change Stream, watching for new changes (insertions, updates, replacements, deletions, and invalidations) in this collection.
1787
1986
  *
1788
- * @since 3.0.0
1987
+ * @remarks
1988
+ * watch() accepts two generic arguments for distinct usecases:
1989
+ * - The first is to override the schema that may be defined for this specific collection
1990
+ * - 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
1991
+ * @example
1992
+ * By just providing the first argument I can type the change to be `ChangeStreamDocument<{ _id: number }>`
1993
+ * ```ts
1994
+ * collection.watch<{ _id: number }>()
1995
+ * .on('change', change => console.log(change._id.toFixed(4)));
1996
+ * ```
1997
+ *
1998
+ * @example
1999
+ * Passing a second argument provides a way to reflect the type changes caused by an advanced pipeline.
2000
+ * Here, we are using a pipeline to have MongoDB filter for insert changes only and add a comment.
2001
+ * No need start from scratch on the ChangeStreamInsertDocument type!
2002
+ * By using an intersection we can save time and ensure defaults remain the same type!
2003
+ * ```ts
2004
+ * collection
2005
+ * .watch<Schema, ChangeStreamInsertDocument<Schema> & { comment: string }>([
2006
+ * { $addFields: { comment: 'big changes' } },
2007
+ * { $match: { operationType: 'insert' } }
2008
+ * ])
2009
+ * .on('change', change => {
2010
+ * change.comment.startsWith('big');
2011
+ * change.operationType === 'insert';
2012
+ * // No need to narrow in code because the generics did that for us!
2013
+ * expectType<Schema>(change.fullDocument);
2014
+ * });
2015
+ * ```
2016
+ *
1789
2017
  * @param pipeline - An array of {@link https://docs.mongodb.com/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.
1790
2018
  * @param options - Optional settings for the command
2019
+ * @typeParam TLocal - Type of the data being detected by the change stream
2020
+ * @typeParam TChange - Type of the whole change stream document emitted
1791
2021
  */
1792
- watch<TLocal = TSchema>(pipeline?: Document[], options?: ChangeStreamOptions): ChangeStream<TLocal>;
2022
+ watch<TLocal extends Document = TSchema, TChange extends Document = ChangeStreamDocument<TLocal>>(pipeline?: Document[], options?: ChangeStreamOptions): ChangeStream<TLocal, TChange>;
1793
2023
  /**
1794
2024
  * Run Map Reduce across a collection. Be aware that the inline option for out will return an array of results not a collection.
1795
2025
  *
@@ -1974,8 +2204,15 @@ export declare interface CommandOperationOptions extends OperationOptions, Write
1974
2204
  /** Collation */
1975
2205
  collation?: CollationOptions;
1976
2206
  maxTimeMS?: number;
1977
- /** A user-provided comment to attach to this command */
1978
- comment?: string | Document;
2207
+ /**
2208
+ * Comment to apply to the operation.
2209
+ *
2210
+ * In server versions pre-4.4, 'comment' must be string. A server
2211
+ * error will be thrown if any other type is provided.
2212
+ *
2213
+ * In server versions 4.4 and above, 'comment' can be any valid BSON type.
2214
+ */
2215
+ comment?: unknown;
1979
2216
  /** Should retry failed writes */
1980
2217
  retryWrites?: boolean;
1981
2218
  dbName?: string;
@@ -2283,8 +2520,12 @@ export declare interface CreateCollectionOptions extends CommandOperationOptions
2283
2520
  pkFactory?: PkFactory;
2284
2521
  /** A document specifying configuration options for timeseries collections. */
2285
2522
  timeseries?: TimeSeriesCollectionOptions;
2286
- /** The number of seconds after which a document in a timeseries collection expires. */
2523
+ /** A document specifying configuration options for clustered collections. For MongoDB 5.3 and above. */
2524
+ clusteredIndex?: ClusteredCollectionOptions;
2525
+ /** The number of seconds after which a document in a timeseries or clustered collection expires. */
2287
2526
  expireAfterSeconds?: number;
2527
+ /** @experimental */
2528
+ encryptedFields?: Document;
2288
2529
  }
2289
2530
 
2290
2531
  /** @public */
@@ -2429,7 +2670,7 @@ export declare class Db {
2429
2670
  * @param pipeline - An array of aggregation stages to be executed
2430
2671
  * @param options - Optional settings for the command
2431
2672
  */
2432
- aggregate<T = Document>(pipeline?: Document[], options?: AggregateOptions): AggregationCursor<T>;
2673
+ aggregate<T extends Document = Document>(pipeline?: Document[], options?: AggregateOptions): AggregationCursor<T>;
2433
2674
  /** Return the Admin db instance */
2434
2675
  admin(): Admin;
2435
2676
  /**
@@ -2589,10 +2830,17 @@ export declare class Db {
2589
2830
  * replacements, deletions, and invalidations) in this database. Will ignore all
2590
2831
  * changes to system collections.
2591
2832
  *
2833
+ * @remarks
2834
+ * watch() accepts two generic arguments for distinct usecases:
2835
+ * - The first is to provide the schema that may be defined for all the collections within this database
2836
+ * - 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
2837
+ *
2592
2838
  * @param pipeline - An array of {@link https://docs.mongodb.com/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.
2593
2839
  * @param options - Optional settings for the command
2840
+ * @typeParam TSchema - Type of the data being detected by the change stream
2841
+ * @typeParam TChange - Type of the whole change stream document emitted
2594
2842
  */
2595
- watch<TSchema = Document>(pipeline?: Document[], options?: ChangeStreamOptions): ChangeStream<TSchema>;
2843
+ watch<TSchema extends Document = Document, TChange extends Document = ChangeStreamDocument<TSchema>>(pipeline?: Document[], options?: ChangeStreamOptions): ChangeStream<TSchema, TChange>;
2596
2844
  /** Return the db logger */
2597
2845
  getLogger(): Logger;
2598
2846
  get logger(): Logger;
@@ -2651,8 +2899,6 @@ export declare interface DeleteOneModel<TSchema extends Document = Document> {
2651
2899
  export declare interface DeleteOptions extends CommandOperationOptions, WriteConcernOptions {
2652
2900
  /** If true, when an insert fails, don't execute the remaining writes. If false, continue with remaining inserts when one fails. */
2653
2901
  ordered?: boolean;
2654
- /** A user-provided comment to attach to this command */
2655
- comment?: string | Document;
2656
2902
  /** Specifies the collation to use for the operation */
2657
2903
  collation?: CollationOptions;
2658
2904
  /** Specify that the update query should only consider plans using the hinted index */
@@ -2681,8 +2927,6 @@ export declare interface DeleteStatement {
2681
2927
  collation?: CollationOptions;
2682
2928
  /** A document or string that specifies the index to use to support the query predicate. */
2683
2929
  hint?: Hint;
2684
- /** A user-provided comment to attach to this command */
2685
- comment?: string | Document;
2686
2930
  }
2687
2931
 
2688
2932
  /* Excluded from this release type: deserialize */
@@ -2708,7 +2952,10 @@ export declare interface DriverInfo {
2708
2952
  }
2709
2953
 
2710
2954
  /** @public */
2711
- export declare type DropCollectionOptions = CommandOperationOptions;
2955
+ export declare interface DropCollectionOptions extends CommandOperationOptions {
2956
+ /** @experimental */
2957
+ encryptedFields?: Document;
2958
+ }
2712
2959
 
2713
2960
  /** @public */
2714
2961
  export declare type DropDatabaseOptions = CommandOperationOptions;
@@ -2847,7 +3094,7 @@ export declare interface FilterOperators<TValue> extends NonObjectIdLikeDocument
2847
3094
  export declare type FinalizeFunction<TKey = ObjectId, TValue = Document> = (key: TKey, reducedValue: TValue) => TValue;
2848
3095
 
2849
3096
  /** @public */
2850
- export declare class FindCursor<TSchema = Document> extends AbstractCursor<TSchema> {
3097
+ export declare class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
2851
3098
  /* Excluded from this release type: [kFilter] */
2852
3099
  /* Excluded from this release type: [kNumReturned] */
2853
3100
  /* Excluded from this release type: [kBuiltOptions] */
@@ -2984,7 +3231,7 @@ export declare class FindCursor<TSchema = Document> extends AbstractCursor<TSche
2984
3231
  * @remarks
2985
3232
  * {@link https://docs.mongodb.com/manual/reference/command/find/#find-cmd-allowdiskuse | find command allowDiskUse documentation}
2986
3233
  */
2987
- allowDiskUse(): this;
3234
+ allowDiskUse(allow?: boolean): this;
2988
3235
  /**
2989
3236
  * Set the collation options for the cursor.
2990
3237
  *
@@ -3111,8 +3358,6 @@ export declare interface FindOptions<TSchema extends Document = Document> extend
3111
3358
  min?: Document;
3112
3359
  /** The exclusive upper bound for a specific index */
3113
3360
  max?: Document;
3114
- /** You can put a $comment field on a query to make looking in the profiler logs simpler. */
3115
- comment?: string | Document;
3116
3361
  /** Number of milliseconds to wait before aborting the query. */
3117
3362
  maxTimeMS?: number;
3118
3363
  /** The maximum amount of time for the server to wait on new documents to satisfy a tailable cursor query. Requires `tailable` and `awaitData` to be true */
@@ -3181,7 +3426,7 @@ export declare class GridFSBucket extends TypedEventEmitter<GridFSBucketEvents>
3181
3426
  *
3182
3427
  * @param id - The id of the file doc
3183
3428
  */
3184
- delete(id: ObjectId): Promise<undefined>;
3429
+ delete(id: ObjectId): Promise<void>;
3185
3430
  delete(id: ObjectId, callback: Callback<void>): void;
3186
3431
  /** Convenience wrapper around find on the files collection */
3187
3432
  find(filter?: Filter<GridFSFile>, options?: FindOptions): FindCursor<GridFSFile>;
@@ -3566,6 +3811,8 @@ export declare type Join<T extends unknown[], D extends string> = T extends [] ?
3566
3811
 
3567
3812
  /* Excluded from this release type: kCursorStream */
3568
3813
 
3814
+ /* Excluded from this release type: kDelayedTimeoutId */
3815
+
3569
3816
  /* Excluded from this release type: kDescription */
3570
3817
 
3571
3818
  /* Excluded from this release type: kDocuments */
@@ -3596,6 +3843,8 @@ export declare type KeysOfOtherType<TSchema, Type> = {
3596
3843
 
3597
3844
  /* Excluded from this release type: KillCursor */
3598
3845
 
3846
+ /* Excluded from this release type: kInit */
3847
+
3599
3848
  /* Excluded from this release type: kInitialized */
3600
3849
 
3601
3850
  /* Excluded from this release type: kInternalClient */
@@ -3670,6 +3919,8 @@ export declare type KeysOfOtherType<TSchema, Type> = {
3670
3919
 
3671
3920
  /* Excluded from this release type: kTransform */
3672
3921
 
3922
+ /* Excluded from this release type: kTxnNumberIncrement */
3923
+
3673
3924
  /* Excluded from this release type: kWaitQueue */
3674
3925
 
3675
3926
  /* Excluded from this release type: kWaitQueue_2 */
@@ -3878,6 +4129,8 @@ export declare type MatchKeysAndValues<TSchema> = Readonly<Partial<TSchema>> & R
3878
4129
 
3879
4130
  export { MaxKey }
3880
4131
 
4132
+ /* Excluded from this release type: MessageHeader */
4133
+
3881
4134
  /* Excluded from this release type: MessageStream */
3882
4135
 
3883
4136
  /* Excluded from this release type: MessageStreamOptions */
@@ -3908,7 +4161,19 @@ export declare class MongoAPIError extends MongoDriverError {
3908
4161
  }
3909
4162
 
3910
4163
  /**
3911
- * An error generated when a batch command is reexecuted after one of the commands in the batch
4164
+ * A error generated when the user attempts to authenticate
4165
+ * via AWS, but fails
4166
+ *
4167
+ * @public
4168
+ * @category Error
4169
+ */
4170
+ export declare class MongoAWSError extends MongoRuntimeError {
4171
+ constructor(message: string);
4172
+ get name(): string;
4173
+ }
4174
+
4175
+ /**
4176
+ * An error generated when a batch command is re-executed after one of the commands in the batch
3912
4177
  * has failed
3913
4178
  *
3914
4179
  * @public
@@ -4076,10 +4341,17 @@ export declare class MongoClient extends TypedEventEmitter<MongoClientEvents> {
4076
4341
  * replacements, deletions, and invalidations) in this cluster. Will ignore all
4077
4342
  * changes to system collections, as well as the local, admin, and config databases.
4078
4343
  *
4344
+ * @remarks
4345
+ * watch() accepts two generic arguments for distinct usecases:
4346
+ * - The first is to provide the schema that may be defined for all the data within the current cluster
4347
+ * - 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
4348
+ *
4079
4349
  * @param pipeline - An array of {@link https://docs.mongodb.com/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.
4080
4350
  * @param options - Optional settings for the command
4351
+ * @typeParam TSchema - Type of the data being detected by the change stream
4352
+ * @typeParam TChange - Type of the whole change stream document emitted
4081
4353
  */
4082
- watch<TSchema = Document>(pipeline?: Document[], options?: ChangeStreamOptions): ChangeStream<TSchema>;
4354
+ watch<TSchema extends Document = Document, TChange extends Document = ChangeStreamDocument<TSchema>>(pipeline?: Document[], options?: ChangeStreamOptions): ChangeStream<TSchema, TChange>;
4083
4355
  /** Return the mongo client logger */
4084
4356
  getLogger(): Logger;
4085
4357
  }
@@ -4245,6 +4517,7 @@ export declare interface MongoClientOptions extends BSONSerializeOptions, Suppor
4245
4517
  proxyPassword?: string;
4246
4518
  /* Excluded from this release type: srvPoller */
4247
4519
  /* Excluded from this release type: connectionType */
4520
+ /* Excluded from this release type: __index */
4248
4521
  }
4249
4522
 
4250
4523
  /* Excluded from this release type: MongoClientPrivate */
@@ -4394,6 +4667,18 @@ export declare class MongoError extends Error {
4394
4667
  get errorLabels(): string[];
4395
4668
  }
4396
4669
 
4670
+ /** @public */
4671
+ export declare const MongoErrorLabel: Readonly<{
4672
+ readonly RetryableWriteError: "RetryableWriteError";
4673
+ readonly TransientTransactionError: "TransientTransactionError";
4674
+ readonly UnknownTransactionCommitResult: "UnknownTransactionCommitResult";
4675
+ readonly ResumableChangeStreamError: "ResumableChangeStreamError";
4676
+ readonly HandshakeError: "HandshakeError";
4677
+ }>;
4678
+
4679
+ /** @public */
4680
+ export declare type MongoErrorLabel = typeof MongoErrorLabel[keyof typeof MongoErrorLabel];
4681
+
4397
4682
  /**
4398
4683
  * An error generated when the user attempts to operate
4399
4684
  * on a session that has expired or has been closed.
@@ -4562,10 +4847,7 @@ export declare interface MongoOptions extends Required<Pick<MongoClientOptions,
4562
4847
  *
4563
4848
  */
4564
4849
  tls: boolean;
4565
- /**
4566
- * Turn these options into a reusable connection URI
4567
- */
4568
- toURI(): string;
4850
+ /* Excluded from this release type: __index */
4569
4851
  }
4570
4852
 
4571
4853
  /**
@@ -4678,6 +4960,27 @@ export declare class MongoTransactionError extends MongoAPIError {
4678
4960
  get name(): string;
4679
4961
  }
4680
4962
 
4963
+ /**
4964
+ * An error generated when a **parsable** unexpected response comes from the server.
4965
+ * This is generally an error where the driver in a state expecting a certain behavior to occur in
4966
+ * the next message from MongoDB but it receives something else.
4967
+ * This error **does not** represent an issue with wire message formatting.
4968
+ *
4969
+ * #### Example
4970
+ * When an operation fails, it is the driver's job to retry it. It must perform serverSelection
4971
+ * again to make sure that it attempts the operation against a server in a good state. If server
4972
+ * selection returns a server that does not support retryable operations, this error is used.
4973
+ * This scenario is unlikely as retryable support would also have been determined on the first attempt
4974
+ * but it is possible the state change could report a selectable server that does not support retries.
4975
+ *
4976
+ * @public
4977
+ * @category Error
4978
+ */
4979
+ export declare class MongoUnexpectedServerResponseError extends MongoRuntimeError {
4980
+ constructor(message: string);
4981
+ get name(): string;
4982
+ }
4983
+
4681
4984
  /**
4682
4985
  * An error thrown when the server reports a writeConcernError
4683
4986
  * @public
@@ -4686,7 +4989,6 @@ export declare class MongoTransactionError extends MongoAPIError {
4686
4989
  export declare class MongoWriteConcernError extends MongoServerError {
4687
4990
  /** The result document (provided if ok: 1) */
4688
4991
  result?: Document;
4689
- errInfo?: Document;
4690
4992
  constructor(message: ErrorDescription, result?: Document);
4691
4993
  get name(): string;
4692
4994
  }
@@ -4721,7 +5023,7 @@ export declare interface MonitorOptions extends Omit<ConnectionOptions, 'id' | '
4721
5023
  */
4722
5024
  export declare type NestedPaths<Type> = Type extends string | number | boolean | Date | RegExp | Buffer | Uint8Array | ((...args: any[]) => any) | {
4723
5025
  _bsontype: string;
4724
- } ? [] : Type extends ReadonlyArray<infer ArrayType> ? [number, ...NestedPaths<ArrayType>] : Type extends Map<string, any> ? [string] : Type extends object ? {
5026
+ } ? [] : Type extends ReadonlyArray<infer ArrayType> ? [] | [number, ...NestedPaths<ArrayType>] : Type extends Map<string, any> ? [string] : Type extends object ? {
4725
5027
  [Key in Extract<keyof Type, string>]: Type[Key] extends Type ? [Key] : Type extends Type[Key] ? [Key] : Type[Key] extends ReadonlyArray<infer ArrayType> ? Type extends ArrayType ? [Key] : ArrayType extends Type ? [Key] : [
4726
5028
  Key,
4727
5029
  ...NestedPaths<Type[Key]>
@@ -4767,7 +5069,7 @@ export declare type OnlyFieldsOfType<TSchema, FieldType = any, AssignableType =
4767
5069
  export declare interface OperationOptions extends BSONSerializeOptions {
4768
5070
  /** Specify ClientSession for this command */
4769
5071
  session?: ClientSession;
4770
- willRetryWrites?: boolean;
5072
+ willRetryWrite?: boolean;
4771
5073
  /** The preferred read preference (ReadPreference.primary, ReadPreference.primary_preferred, ReadPreference.secondary, ReadPreference.secondary_preferred, ReadPreference.nearest). */
4772
5074
  readPreference?: ReadPreferenceLike;
4773
5075
  /* Excluded from this release type: bypassPinningCheck */
@@ -4777,17 +5079,20 @@ export declare interface OperationOptions extends BSONSerializeOptions {
4777
5079
  /* Excluded from this release type: OperationParent */
4778
5080
 
4779
5081
  /**
4780
- * Represents a specific point in time on a server. Can be retrieved by using {@link Db#command}
5082
+ * Represents a specific point in time on a server. Can be retrieved by using `db.command()`
4781
5083
  * @public
4782
- * @remarks
4783
- * See {@link https://docs.mongodb.com/manual/reference/method/db.runCommand/#response| Run Command Response}
5084
+ * @see https://docs.mongodb.com/manual/reference/method/db.runCommand/#response
4784
5085
  */
4785
5086
  export declare type OperationTime = Timestamp;
4786
5087
 
4787
5088
  /* Excluded from this release type: OpGetMoreOptions */
4788
5089
 
5090
+ /* Excluded from this release type: OpMsgOptions */
5091
+
4789
5092
  /* Excluded from this release type: OpQueryOptions */
4790
5093
 
5094
+ /* Excluded from this release type: OpResponseOptions */
5095
+
4791
5096
  /**
4792
5097
  * Add an optional _id field to an object shaped type
4793
5098
  * @public
@@ -5106,6 +5411,8 @@ export declare interface ReplaceOptions extends CommandOperationOptions {
5106
5411
  let?: Document;
5107
5412
  }
5108
5413
 
5414
+ /* Excluded from this release type: Response */
5415
+
5109
5416
  /** @public */
5110
5417
  export declare interface ResumeOptions {
5111
5418
  startAtOperationTime?: Timestamp;
@@ -5113,10 +5420,13 @@ export declare interface ResumeOptions {
5113
5420
  maxAwaitTimeMS?: number;
5114
5421
  collation?: CollationOptions;
5115
5422
  readPreference?: ReadPreference;
5423
+ resumeAfter?: ResumeToken;
5424
+ startAfter?: ResumeToken;
5116
5425
  }
5117
5426
 
5118
5427
  /**
5119
- * Represents the logical starting point for a new or resuming {@link https://docs.mongodb.com/manual/changeStreams/#std-label-change-stream-resume| Change Stream} on the server.
5428
+ * Represents the logical starting point for a new ChangeStream or resuming a ChangeStream on the server.
5429
+ * @see https://www.mongodb.com/docs/manual/changeStreams/#std-label-change-stream-resume
5120
5430
  * @public
5121
5431
  */
5122
5432
  export declare type ResumeToken = unknown;
@@ -5387,6 +5697,7 @@ export declare class ServerSession {
5387
5697
  * @param sessionTimeoutMinutes - The server's "logicalSessionTimeoutMinutes"
5388
5698
  */
5389
5699
  hasTimedOut(sessionTimeoutMinutes: number): boolean;
5700
+ /* Excluded from this release type: clone */
5390
5701
  }
5391
5702
 
5392
5703
  /** @public */
@@ -5469,7 +5780,7 @@ export declare class StreamDescription {
5469
5780
  __nodejs_mock_server__?: boolean;
5470
5781
  zlibCompressionLevel?: number;
5471
5782
  constructor(address: string, options?: StreamDescriptionOptions);
5472
- receiveResponse(response: Document): void;
5783
+ receiveResponse(response: Document | null): void;
5473
5784
  }
5474
5785
 
5475
5786
  /** @public */
@@ -5624,6 +5935,7 @@ export declare interface TopologyOptions extends BSONSerializeOptions, ServerOpt
5624
5935
  metadata: ClientMetadata;
5625
5936
  /** MongoDB server API version */
5626
5937
  serverApi?: ServerApi;
5938
+ /* Excluded from this release type: __index */
5627
5939
  }
5628
5940
 
5629
5941
  /* Excluded from this release type: TopologyPrivate */
@@ -5737,7 +6049,7 @@ export declare class TypedEventEmitter<Events extends EventsDescription> extends
5737
6049
  /** @public */
5738
6050
  export declare class UnorderedBulkOperation extends BulkOperationBase {
5739
6051
  constructor(collection: Collection, options: BulkWriteOptions);
5740
- handleWriteError(callback: Callback, writeResult: BulkWriteResult): boolean | undefined;
6052
+ handleWriteError(callback: Callback, writeResult: BulkWriteResult): boolean;
5741
6053
  addToOperationsList(batchType: BatchType, document: Document | UpdateStatement | DeleteStatement): this;
5742
6054
  }
5743
6055
 
@@ -5747,11 +6059,24 @@ export declare interface UpdateDescription<TSchema extends Document = Document>
5747
6059
  * A document containing key:value pairs of names of the fields that were
5748
6060
  * changed, and the new value for those fields.
5749
6061
  */
5750
- updatedFields: Partial<TSchema>;
6062
+ updatedFields?: Partial<TSchema>;
5751
6063
  /**
5752
6064
  * An array of field names that were removed from the document.
5753
6065
  */
5754
- removedFields: string[];
6066
+ removedFields?: string[];
6067
+ /**
6068
+ * An array of documents which record array truncations performed with pipeline-based updates using one or more of the following stages:
6069
+ * - $addFields
6070
+ * - $set
6071
+ * - $replaceRoot
6072
+ * - $replaceWith
6073
+ */
6074
+ truncatedArrays?: Array<{
6075
+ /** The name of the truncated field. */
6076
+ field: string;
6077
+ /** The number of elements in the truncated array. */
6078
+ newSize: number;
6079
+ }>;
5755
6080
  }
5756
6081
 
5757
6082
  /** @public */
@@ -6020,7 +6345,7 @@ export declare type WithId<TSchema> = EnhancedOmit<TSchema, '_id'> & {
6020
6345
  export declare type WithoutId<TSchema> = Omit<TSchema, '_id'>;
6021
6346
 
6022
6347
  /** @public */
6023
- export declare type WithSessionCallback = (session: ClientSession) => Promise<any> | void;
6348
+ export declare type WithSessionCallback = (session: ClientSession) => Promise<any>;
6024
6349
 
6025
6350
  /** @public */
6026
6351
  export declare type WithTransactionCallback<T = void> = (session: ClientSession) => Promise<T>;