mongodb 6.16.0 → 6.17.0-dev.20250605.sha.57ef31be

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 (130) hide show
  1. package/README.md +2 -0
  2. package/lib/beta.d.ts +160 -49
  3. package/lib/bulk/common.js +4 -4
  4. package/lib/bulk/common.js.map +1 -1
  5. package/lib/change_stream.js.map +1 -1
  6. package/lib/client-side-encryption/auto_encrypter.js +5 -2
  7. package/lib/client-side-encryption/auto_encrypter.js.map +1 -1
  8. package/lib/client-side-encryption/client_encryption.js.map +1 -1
  9. package/lib/client-side-encryption/state_machine.js +1 -1
  10. package/lib/client-side-encryption/state_machine.js.map +1 -1
  11. package/lib/cmap/auth/mongodb_oidc/automated_callback_workflow.js +6 -0
  12. package/lib/cmap/auth/mongodb_oidc/automated_callback_workflow.js.map +1 -1
  13. package/lib/cmap/auth/mongodb_oidc/azure_machine_workflow.js +21 -33
  14. package/lib/cmap/auth/mongodb_oidc/azure_machine_workflow.js.map +1 -1
  15. package/lib/cmap/auth/mongodb_oidc/gcp_machine_workflow.js +14 -21
  16. package/lib/cmap/auth/mongodb_oidc/gcp_machine_workflow.js.map +1 -1
  17. package/lib/cmap/auth/mongodb_oidc/k8s_machine_workflow.js +19 -26
  18. package/lib/cmap/auth/mongodb_oidc/k8s_machine_workflow.js.map +1 -1
  19. package/lib/cmap/auth/mongodb_oidc/token_machine_workflow.js +12 -24
  20. package/lib/cmap/auth/mongodb_oidc/token_machine_workflow.js.map +1 -1
  21. package/lib/cmap/auth/mongodb_oidc.js +5 -4
  22. package/lib/cmap/auth/mongodb_oidc.js.map +1 -1
  23. package/lib/cmap/commands.js +10 -8
  24. package/lib/cmap/commands.js.map +1 -1
  25. package/lib/cmap/connect.js +4 -3
  26. package/lib/cmap/connect.js.map +1 -1
  27. package/lib/cmap/connection.js +8 -3
  28. package/lib/cmap/connection.js.map +1 -1
  29. package/lib/cmap/connection_pool.js +6 -1
  30. package/lib/cmap/connection_pool.js.map +1 -1
  31. package/lib/cmap/handshake/client_metadata.js +1 -1
  32. package/lib/cmap/handshake/client_metadata.js.map +1 -1
  33. package/lib/cmap/wire_protocol/compression.js.map +1 -1
  34. package/lib/cmap/wire_protocol/constants.js +2 -2
  35. package/lib/cmap/wire_protocol/on_data.js +4 -0
  36. package/lib/cmap/wire_protocol/on_data.js.map +1 -1
  37. package/lib/cmap/wire_protocol/on_demand/document.js +16 -15
  38. package/lib/cmap/wire_protocol/on_demand/document.js.map +1 -1
  39. package/lib/cmap/wire_protocol/responses.js +11 -4
  40. package/lib/cmap/wire_protocol/responses.js.map +1 -1
  41. package/lib/collection.js.map +1 -1
  42. package/lib/connection_string.js +4 -0
  43. package/lib/connection_string.js.map +1 -1
  44. package/lib/constants.js +0 -1
  45. package/lib/constants.js.map +1 -1
  46. package/lib/cursor/abstract_cursor.js.map +1 -1
  47. package/lib/encrypter.js +3 -7
  48. package/lib/encrypter.js.map +1 -1
  49. package/lib/error.js +28 -1
  50. package/lib/error.js.map +1 -1
  51. package/lib/index.js +4 -3
  52. package/lib/index.js.map +1 -1
  53. package/lib/mongo_client.js +66 -20
  54. package/lib/mongo_client.js.map +1 -1
  55. package/lib/operations/aggregate.js +0 -1
  56. package/lib/operations/aggregate.js.map +1 -1
  57. package/lib/operations/client_bulk_write/command_builder.js +20 -13
  58. package/lib/operations/client_bulk_write/command_builder.js.map +1 -1
  59. package/lib/operations/distinct.js +1 -0
  60. package/lib/operations/distinct.js.map +1 -1
  61. package/lib/operations/find_and_modify.js +1 -1
  62. package/lib/operations/find_and_modify.js.map +1 -1
  63. package/lib/operations/rename.js.map +1 -1
  64. package/lib/operations/run_command.js.map +1 -1
  65. package/lib/operations/search_indexes/create.js.map +1 -1
  66. package/lib/operations/search_indexes/drop.js.map +1 -1
  67. package/lib/operations/search_indexes/update.js.map +1 -1
  68. package/lib/operations/update.js +6 -2
  69. package/lib/operations/update.js.map +1 -1
  70. package/lib/sdam/server.js +4 -1
  71. package/lib/sdam/server.js.map +1 -1
  72. package/lib/sdam/topology.js +9 -4
  73. package/lib/sdam/topology.js.map +1 -1
  74. package/lib/sort.js +13 -6
  75. package/lib/sort.js.map +1 -1
  76. package/lib/utils.js +15 -2
  77. package/lib/utils.js.map +1 -1
  78. package/lib/write_concern.js +2 -4
  79. package/lib/write_concern.js.map +1 -1
  80. package/mongodb.d.ts +160 -49
  81. package/package.json +21 -21
  82. package/src/bulk/common.ts +14 -11
  83. package/src/change_stream.ts +38 -13
  84. package/src/client-side-encryption/auto_encrypter.ts +10 -2
  85. package/src/client-side-encryption/client_encryption.ts +5 -0
  86. package/src/client-side-encryption/state_machine.ts +8 -5
  87. package/src/cmap/auth/mongodb_oidc/automated_callback_workflow.ts +6 -0
  88. package/src/cmap/auth/mongodb_oidc/azure_machine_workflow.ts +23 -35
  89. package/src/cmap/auth/mongodb_oidc/gcp_machine_workflow.ts +16 -23
  90. package/src/cmap/auth/mongodb_oidc/k8s_machine_workflow.ts +17 -25
  91. package/src/cmap/auth/mongodb_oidc/token_machine_workflow.ts +11 -24
  92. package/src/cmap/auth/mongodb_oidc.ts +13 -8
  93. package/src/cmap/commands.ts +31 -16
  94. package/src/cmap/connect.ts +4 -3
  95. package/src/cmap/connection.ts +11 -4
  96. package/src/cmap/connection_pool.ts +8 -1
  97. package/src/cmap/handshake/client_metadata.ts +5 -1
  98. package/src/cmap/wire_protocol/compression.ts +2 -1
  99. package/src/cmap/wire_protocol/constants.ts +2 -2
  100. package/src/cmap/wire_protocol/on_data.ts +5 -0
  101. package/src/cmap/wire_protocol/on_demand/document.ts +20 -15
  102. package/src/cmap/wire_protocol/responses.ts +10 -10
  103. package/src/collection.ts +2 -1
  104. package/src/connection_string.ts +4 -0
  105. package/src/constants.ts +0 -1
  106. package/src/cursor/abstract_cursor.ts +6 -4
  107. package/src/encrypter.ts +3 -10
  108. package/src/error.ts +28 -0
  109. package/src/index.ts +3 -0
  110. package/src/mongo_client.ts +73 -21
  111. package/src/operations/aggregate.ts +0 -1
  112. package/src/operations/client_bulk_write/command_builder.ts +32 -14
  113. package/src/operations/client_bulk_write/common.ts +5 -0
  114. package/src/operations/distinct.ts +1 -0
  115. package/src/operations/find_and_modify.ts +1 -1
  116. package/src/operations/rename.ts +8 -5
  117. package/src/operations/run_command.ts +17 -4
  118. package/src/operations/search_indexes/create.ts +6 -4
  119. package/src/operations/search_indexes/drop.ts +6 -4
  120. package/src/operations/search_indexes/update.ts +8 -5
  121. package/src/operations/update.ts +12 -3
  122. package/src/sdam/server.ts +5 -1
  123. package/src/sdam/topology.ts +10 -4
  124. package/src/sort.ts +32 -23
  125. package/src/utils.ts +29 -9
  126. package/src/write_concern.ts +2 -4
  127. package/tsconfig.json +2 -1
  128. package/lib/cmap/auth/mongodb_oidc/machine_workflow.js +0 -110
  129. package/lib/cmap/auth/mongodb_oidc/machine_workflow.js.map +0 -1
  130. package/src/cmap/auth/mongodb_oidc/machine_workflow.ts +0 -142
package/mongodb.d.ts CHANGED
@@ -770,6 +770,10 @@ export declare interface AutoEncryptionOptions {
770
770
  bypassAutoEncryption?: boolean;
771
771
  /** Allows users to bypass query analysis */
772
772
  bypassQueryAnalysis?: boolean;
773
+ /**
774
+ * Sets the expiration time for the DEK in the cache in milliseconds. Defaults to 60000. 0 means no timeout.
775
+ */
776
+ keyExpirationMS?: number;
773
777
  options?: {
774
778
  /** An optional hook to catch logging messages from the underlying encryption engine */
775
779
  logger?: (level: AutoEncryptionLoggerLevel, message: string) => void;
@@ -1002,10 +1006,10 @@ export declare type BSONTypeAlias = keyof typeof BSONType;
1002
1006
 
1003
1007
  /** @public */
1004
1008
  export declare abstract class BulkOperationBase {
1005
- private collection;
1006
1009
  isOrdered: boolean;
1007
1010
  /* Excluded from this release type: s */
1008
1011
  operationId?: number;
1012
+ private collection;
1009
1013
  /* Excluded from this release type: __constructor */
1010
1014
  /**
1011
1015
  * Add a single insert document to the bulk operation
@@ -1142,7 +1146,7 @@ export declare class BulkWriteResult {
1142
1146
  getRawResponse(): Document;
1143
1147
  /** Returns true if the bulk operation contains a write error */
1144
1148
  hasWriteErrors(): boolean;
1145
- /** Returns the number of write errors off the bulk operation */
1149
+ /** Returns the number of write errors from the bulk operation */
1146
1150
  getWriteErrorCount(): number;
1147
1151
  /** Returns a specific write error object */
1148
1152
  getWriteErrorAt(index: number): WriteError | undefined;
@@ -1268,7 +1272,7 @@ export declare class ChangeStream<TSchema extends Document = Document, TChange e
1268
1272
  * @public
1269
1273
  * @see https://www.mongodb.com/docs/manual/reference/change-events/modify/#mongodb-data-modify
1270
1274
  */
1271
- export declare interface ChangeStreamCollModDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID {
1275
+ export declare interface ChangeStreamCollModDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID, ChangeStreamDocumentWallTime {
1272
1276
  /** Describes the type of operation represented in this change notification */
1273
1277
  operationType: 'modify';
1274
1278
  }
@@ -1277,7 +1281,7 @@ export declare interface ChangeStreamCollModDocument extends ChangeStreamDocumen
1277
1281
  * @public
1278
1282
  * @see https://www.mongodb.com/docs/manual/reference/change-events/create/#mongodb-data-create
1279
1283
  */
1280
- export declare interface ChangeStreamCreateDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID {
1284
+ export declare interface ChangeStreamCreateDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID, ChangeStreamDocumentWallTime {
1281
1285
  /** Describes the type of operation represented in this change notification */
1282
1286
  operationType: 'create';
1283
1287
  /**
@@ -1293,7 +1297,7 @@ export declare interface ChangeStreamCreateDocument extends ChangeStreamDocument
1293
1297
  * @public
1294
1298
  * @see https://www.mongodb.com/docs/manual/reference/change-events/createIndexes/#mongodb-data-createIndexes
1295
1299
  */
1296
- export declare interface ChangeStreamCreateIndexDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID, ChangeStreamDocumentOperationDescription {
1300
+ export declare interface ChangeStreamCreateIndexDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID, ChangeStreamDocumentOperationDescription, ChangeStreamDocumentWallTime {
1297
1301
  /** Describes the type of operation represented in this change notification */
1298
1302
  operationType: 'createIndexes';
1299
1303
  }
@@ -1306,7 +1310,7 @@ export declare interface ChangeStreamCreateIndexDocument extends ChangeStreamDoc
1306
1310
  * @public
1307
1311
  * @see https://www.mongodb.com/docs/manual/reference/change-events/#delete-event
1308
1312
  */
1309
- export declare interface ChangeStreamDeleteDocument<TSchema extends Document = Document> extends ChangeStreamDocumentCommon, ChangeStreamDocumentKey<TSchema>, ChangeStreamDocumentCollectionUUID {
1313
+ export declare interface ChangeStreamDeleteDocument<TSchema extends Document = Document> extends ChangeStreamDocumentCommon, ChangeStreamDocumentKey<TSchema>, ChangeStreamDocumentCollectionUUID, ChangeStreamDocumentWallTime {
1310
1314
  /** Describes the type of operation represented in this change notification */
1311
1315
  operationType: 'delete';
1312
1316
  /** Namespace the delete event occurred on */
@@ -1399,11 +1403,21 @@ export declare interface ChangeStreamDocumentOperationDescription {
1399
1403
  operationDescription?: Document;
1400
1404
  }
1401
1405
 
1406
+ /** @public */
1407
+ export declare interface ChangeStreamDocumentWallTime {
1408
+ /**
1409
+ * The server date and time of the database operation.
1410
+ * wallTime differs from clusterTime in that clusterTime is a timestamp taken from the oplog entry associated with the database operation event.
1411
+ * @sinceServerVersion 6.0.0
1412
+ */
1413
+ wallTime?: Date;
1414
+ }
1415
+
1402
1416
  /**
1403
1417
  * @public
1404
1418
  * @see https://www.mongodb.com/docs/manual/reference/change-events/#dropdatabase-event
1405
1419
  */
1406
- export declare interface ChangeStreamDropDatabaseDocument extends ChangeStreamDocumentCommon {
1420
+ export declare interface ChangeStreamDropDatabaseDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentWallTime {
1407
1421
  /** Describes the type of operation represented in this change notification */
1408
1422
  operationType: 'dropDatabase';
1409
1423
  /** The database dropped */
@@ -1416,7 +1430,7 @@ export declare interface ChangeStreamDropDatabaseDocument extends ChangeStreamDo
1416
1430
  * @public
1417
1431
  * @see https://www.mongodb.com/docs/manual/reference/change-events/#drop-event
1418
1432
  */
1419
- export declare interface ChangeStreamDropDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID {
1433
+ export declare interface ChangeStreamDropDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID, ChangeStreamDocumentWallTime {
1420
1434
  /** Describes the type of operation represented in this change notification */
1421
1435
  operationType: 'drop';
1422
1436
  /** Namespace the drop event occurred on */
@@ -1428,7 +1442,7 @@ export declare interface ChangeStreamDropDocument extends ChangeStreamDocumentCo
1428
1442
  * @public
1429
1443
  * @see https://www.mongodb.com/docs/manual/reference/change-events/dropIndexes/#mongodb-data-dropIndexes
1430
1444
  */
1431
- export declare interface ChangeStreamDropIndexDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID, ChangeStreamDocumentOperationDescription {
1445
+ export declare interface ChangeStreamDropIndexDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID, ChangeStreamDocumentOperationDescription, ChangeStreamDocumentWallTime {
1432
1446
  /** Describes the type of operation represented in this change notification */
1433
1447
  operationType: 'dropIndexes';
1434
1448
  }
@@ -1455,7 +1469,7 @@ export declare type ChangeStreamEvents<TSchema extends Document = Document, TCha
1455
1469
  * @public
1456
1470
  * @see https://www.mongodb.com/docs/manual/reference/change-events/#insert-event
1457
1471
  */
1458
- export declare interface ChangeStreamInsertDocument<TSchema extends Document = Document> extends ChangeStreamDocumentCommon, ChangeStreamDocumentKey<TSchema>, ChangeStreamDocumentCollectionUUID {
1472
+ export declare interface ChangeStreamInsertDocument<TSchema extends Document = Document> extends ChangeStreamDocumentCommon, ChangeStreamDocumentKey<TSchema>, ChangeStreamDocumentCollectionUUID, ChangeStreamDocumentWallTime {
1459
1473
  /** Describes the type of operation represented in this change notification */
1460
1474
  operationType: 'insert';
1461
1475
  /** This key will contain the document being inserted */
@@ -1468,7 +1482,7 @@ export declare interface ChangeStreamInsertDocument<TSchema extends Document = D
1468
1482
  * @public
1469
1483
  * @see https://www.mongodb.com/docs/manual/reference/change-events/#invalidate-event
1470
1484
  */
1471
- export declare interface ChangeStreamInvalidateDocument extends ChangeStreamDocumentCommon {
1485
+ export declare interface ChangeStreamInvalidateDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentWallTime {
1472
1486
  /** Describes the type of operation represented in this change notification */
1473
1487
  operationType: 'invalidate';
1474
1488
  }
@@ -1559,7 +1573,7 @@ export declare interface ChangeStreamRefineCollectionShardKeyDocument extends Ch
1559
1573
  * @public
1560
1574
  * @see https://www.mongodb.com/docs/manual/reference/change-events/#rename-event
1561
1575
  */
1562
- export declare interface ChangeStreamRenameDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID {
1576
+ export declare interface ChangeStreamRenameDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID, ChangeStreamDocumentWallTime {
1563
1577
  /** Describes the type of operation represented in this change notification */
1564
1578
  operationType: 'rename';
1565
1579
  /** The new name for the `ns.coll` collection */
@@ -1575,7 +1589,7 @@ export declare interface ChangeStreamRenameDocument extends ChangeStreamDocument
1575
1589
  * @public
1576
1590
  * @see https://www.mongodb.com/docs/manual/reference/change-events/#replace-event
1577
1591
  */
1578
- export declare interface ChangeStreamReplaceDocument<TSchema extends Document = Document> extends ChangeStreamDocumentCommon, ChangeStreamDocumentKey<TSchema> {
1592
+ export declare interface ChangeStreamReplaceDocument<TSchema extends Document = Document> extends ChangeStreamDocumentCommon, ChangeStreamDocumentKey<TSchema>, ChangeStreamDocumentWallTime {
1579
1593
  /** Describes the type of operation represented in this change notification */
1580
1594
  operationType: 'replace';
1581
1595
  /** The fullDocument of a replace event represents the document after the insert of the replacement document */
@@ -1605,7 +1619,7 @@ export declare interface ChangeStreamReshardCollectionDocument extends ChangeStr
1605
1619
  * @public
1606
1620
  * @see https://www.mongodb.com/docs/manual/reference/change-events/shardCollection/#mongodb-data-shardCollection
1607
1621
  */
1608
- export declare interface ChangeStreamShardCollectionDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID, ChangeStreamDocumentOperationDescription {
1622
+ export declare interface ChangeStreamShardCollectionDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID, ChangeStreamDocumentOperationDescription, ChangeStreamDocumentWallTime {
1609
1623
  /** Describes the type of operation represented in this change notification */
1610
1624
  operationType: 'shardCollection';
1611
1625
  }
@@ -1622,7 +1636,7 @@ export declare interface ChangeStreamSplitEvent {
1622
1636
  * @public
1623
1637
  * @see https://www.mongodb.com/docs/manual/reference/change-events/#update-event
1624
1638
  */
1625
- export declare interface ChangeStreamUpdateDocument<TSchema extends Document = Document> extends ChangeStreamDocumentCommon, ChangeStreamDocumentKey<TSchema>, ChangeStreamDocumentCollectionUUID {
1639
+ export declare interface ChangeStreamUpdateDocument<TSchema extends Document = Document> extends ChangeStreamDocumentCommon, ChangeStreamDocumentKey<TSchema>, ChangeStreamDocumentCollectionUUID, ChangeStreamDocumentWallTime {
1626
1640
  /** Describes the type of operation represented in this change notification */
1627
1641
  operationType: 'update';
1628
1642
  /**
@@ -2164,6 +2178,10 @@ export declare interface ClientEncryptionOptions {
2164
2178
  * TLS options for kms providers to use.
2165
2179
  */
2166
2180
  tlsOptions?: CSFLEKMSTlsOptions;
2181
+ /**
2182
+ * Sets the expiration time for the DEK in the cache in milliseconds. Defaults to 60000. 0 means no timeout.
2183
+ */
2184
+ keyExpirationMS?: number;
2167
2185
  /**
2168
2186
  * @experimental
2169
2187
  *
@@ -2307,6 +2325,8 @@ export declare interface ClientReplaceOneModel<TSchema> extends ClientWriteModel
2307
2325
  hint?: Hint;
2308
2326
  /** When true, creates a new document if no document matches the query. */
2309
2327
  upsert?: boolean;
2328
+ /** Specifies the sort order for the documents matched by the filter. */
2329
+ sort?: Sort;
2310
2330
  }
2311
2331
 
2312
2332
  /**
@@ -2539,6 +2559,8 @@ export declare interface ClientUpdateOneModel<TSchema> extends ClientWriteModel
2539
2559
  hint?: Hint;
2540
2560
  /** When true, creates a new document if no document matches the query. */
2541
2561
  upsert?: boolean;
2562
+ /** Specifies the sort order for the documents matched by the filter. */
2563
+ sort?: Sort;
2542
2564
  }
2543
2565
 
2544
2566
  /** @public */
@@ -2739,7 +2761,9 @@ export declare class Collection<TSchema extends Document = Document> {
2739
2761
  * @param update - The modifications to apply
2740
2762
  * @param options - Optional settings for the command
2741
2763
  */
2742
- updateOne(filter: Filter<TSchema>, update: UpdateFilter<TSchema> | Document[], options?: UpdateOptions): Promise<UpdateResult<TSchema>>;
2764
+ updateOne(filter: Filter<TSchema>, update: UpdateFilter<TSchema> | Document[], options?: UpdateOptions & {
2765
+ sort?: Sort;
2766
+ }): Promise<UpdateResult<TSchema>>;
2743
2767
  /**
2744
2768
  * Replace a document in a collection with another document
2745
2769
  *
@@ -5364,7 +5388,7 @@ export declare interface KMSProviders {
5364
5388
  /* Excluded from this release type: LegacyTimeoutContextOptions */
5365
5389
 
5366
5390
  /** @public */
5367
- export declare const LEGAL_TCP_SOCKET_OPTIONS: readonly ["autoSelectFamily", "autoSelectFamilyAttemptTimeout", "family", "hints", "localAddress", "localPort", "lookup"];
5391
+ export declare const LEGAL_TCP_SOCKET_OPTIONS: readonly ["autoSelectFamily", "autoSelectFamilyAttemptTimeout", "keepAliveInitialDelay", "family", "hints", "localAddress", "localPort", "lookup"];
5368
5392
 
5369
5393
  /** @public */
5370
5394
  export declare const LEGAL_TLS_SOCKET_OPTIONS: readonly ["allowPartialTrustChain", "ALPNProtocols", "ca", "cert", "checkServerIdentity", "ciphers", "crl", "ecdhCurve", "key", "minDHSize", "passphrase", "pfx", "rejectUnauthorized", "secureContext", "secureProtocol", "servername", "session"];
@@ -5674,22 +5698,35 @@ export declare class MongoChangeStreamError extends MongoRuntimeError {
5674
5698
  }
5675
5699
 
5676
5700
  /**
5677
- * The **MongoClient** class is a class that allows for making Connections to MongoDB.
5678
5701
  * @public
5679
5702
  *
5703
+ * The **MongoClient** class is a class that allows for making Connections to MongoDB.
5704
+ *
5705
+ * **NOTE:** The programmatically provided options take precedence over the URI options.
5706
+ *
5680
5707
  * @remarks
5681
- * The programmatically provided options take precedence over the URI options.
5708
+ *
5709
+ * A MongoClient is the entry point to connecting to a MongoDB server.
5710
+ *
5711
+ * It handles a multitude of features on your application's behalf:
5712
+ * - **Server Host Connection Configuration**: A MongoClient is responsible for reading TLS cert, ca, and crl files if provided.
5713
+ * - **SRV Record Polling**: A "`mongodb+srv`" style connection string is used to have the MongoClient resolve DNS SRV records of all server hostnames which the driver periodically monitors for changes and adjusts its current view of hosts correspondingly.
5714
+ * - **Server Monitoring**: The MongoClient automatically keeps monitoring the health of server nodes in your cluster to reach out to the correct and lowest latency one available.
5715
+ * - **Connection Pooling**: To avoid paying the cost of rebuilding a connection to the server on every operation the MongoClient keeps idle connections preserved for reuse.
5716
+ * - **Session Pooling**: The MongoClient creates logical sessions that enable retryable writes, causal consistency, and transactions. It handles pooling these sessions for reuse in subsequent operations.
5717
+ * - **Cursor Operations**: A MongoClient's cursors use the health monitoring system to send the request for more documents to the same server the query began on.
5718
+ * - **Mongocryptd process**: When using auto encryption, a MongoClient will launch a `mongocryptd` instance for handling encryption if the mongocrypt shared library isn't in use.
5719
+ *
5720
+ * There are many more features of a MongoClient that are not listed above.
5721
+ *
5722
+ * In order to enable these features, a number of asynchronous Node.js resources are established by the driver: Timers, FS Requests, Sockets, etc.
5723
+ * For details on cleanup, please refer to the MongoClient `close()` documentation.
5682
5724
  *
5683
5725
  * @example
5684
5726
  * ```ts
5685
5727
  * import { MongoClient } from 'mongodb';
5686
- *
5687
5728
  * // Enable command monitoring for debugging
5688
- * const client = new MongoClient('mongodb://localhost:27017', { monitorCommands: true });
5689
- *
5690
- * client.on('commandStarted', started => console.log(started));
5691
- * client.db().collection('pets');
5692
- * await client.insertOne({ name: 'spot', kind: 'dog' });
5729
+ * const client = new MongoClient('mongodb://localhost:27017?appName=mflix', { monitorCommands: true });
5693
5730
  * ```
5694
5731
  */
5695
5732
  export declare class MongoClient extends TypedEventEmitter<MongoClientEvents> implements AsyncDisposable_2 {
@@ -5741,19 +5778,51 @@ export declare class MongoClient extends TypedEventEmitter<MongoClientEvents> im
5741
5778
  connect(): Promise<this>;
5742
5779
  /* Excluded from this release type: _connect */
5743
5780
  /**
5744
- * Cleans up client-side resources used by the MongoCLient and . This includes:
5745
- *
5746
- * - Closes all open, unused connections (see note).
5747
- * - Ends all in-use sessions with {@link ClientSession#endSession|ClientSession.endSession()}.
5748
- * - Ends all unused sessions server-side.
5749
- * - Cleans up any resources being used for auto encryption if auto encryption is enabled.
5750
- *
5751
- * @remarks Any in-progress operations are not killed and any connections used by in progress operations
5752
- * will be cleaned up lazily as operations finish.
5753
- *
5754
- * @param force - Force close, emitting no events
5755
- */
5756
- close(force?: boolean): Promise<void>;
5781
+ * Cleans up resources managed by the MongoClient.
5782
+ *
5783
+ * The close method clears and closes all resources whose lifetimes are managed by the MongoClient.
5784
+ * Please refer to the `MongoClient` class documentation for a high level overview of the client's key features and responsibilities.
5785
+ *
5786
+ * **However,** the close method does not handle the cleanup of resources explicitly created by the user.
5787
+ * Any user-created driver resource with its own `close()` method should be explicitly closed by the user before calling MongoClient.close().
5788
+ * This method is written as a "best effort" attempt to leave behind the least amount of resources server-side when possible.
5789
+ *
5790
+ * The following list defines ideal preconditions and consequent pitfalls if they are not met.
5791
+ * The MongoClient, ClientSession, Cursors and ChangeStreams all support [explicit resource management](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html).
5792
+ * By using explicit resource management to manage the lifetime of driver resources instead of manually managing their lifetimes, the pitfalls outlined below can be avoided.
5793
+ *
5794
+ * The close method performs the following in the order listed:
5795
+ * - Client-side:
5796
+ * - **Close in-use connections**: Any connections that are currently waiting on a response from the server will be closed.
5797
+ * This is performed _first_ to avoid reaching the next step (server-side clean up) and having no available connections to check out.
5798
+ * - _Ideal_: All operations have been awaited or cancelled, and the outcomes, regardless of success or failure, have been processed before closing the client servicing the operation.
5799
+ * - _Pitfall_: When `client.close()` is called and all connections are in use, after closing them, the client must create new connections for cleanup operations, which comes at the cost of new TLS/TCP handshakes and authentication steps.
5800
+ * - Server-side:
5801
+ * - **Close active cursors**: All cursors that haven't been completed will have a `killCursor` operation sent to the server they were initialized on, freeing the server-side resource.
5802
+ * - _Ideal_: Cursors are explicitly closed or completed before `client.close()` is called.
5803
+ * - _Pitfall_: `killCursors` may have to build a new connection if the in-use closure ended all pooled connections.
5804
+ * - **End active sessions**: In-use sessions created with `client.startSession()` or `client.withSession()` or implicitly by the driver will have their `.endSession()` method called.
5805
+ * Contrary to the name of the method, `endSession()` returns the session to the client's pool of sessions rather than end them on the server.
5806
+ * - _Ideal_: Transaction outcomes are awaited and their corresponding explicit sessions are ended before `client.close()` is called.
5807
+ * - _Pitfall_: **This step aborts in-progress transactions**. It is advisable to observe the outcome of a transaction before closing your client.
5808
+ * - **End all pooled sessions**: The `endSessions` command with all session IDs the client has pooled is sent to the server to inform the cluster it can clean them up.
5809
+ * - _Ideal_: No user intervention is expected.
5810
+ * - _Pitfall_: None.
5811
+ *
5812
+ * The remaining shutdown is of the MongoClient resources that are intended to be entirely internal but is documented here as their existence relates to the JS event loop.
5813
+ *
5814
+ * - Client-side (again):
5815
+ * - **Stop all server monitoring**: Connections kept live for detecting cluster changes and roundtrip time measurements are shutdown.
5816
+ * - **Close all pooled connections**: Each server node in the cluster has a corresponding connection pool and all connections in the pool are closed. Any operations waiting to check out a connection will have an error thrown instead of a connection returned.
5817
+ * - **Clear out server selection queue**: Any operations that are in the process of waiting for a server to be selected will have an error thrown instead of a server returned.
5818
+ * - **Close encryption-related resources**: An internal MongoClient created for communicating with `mongocryptd` or other encryption purposes is closed. (Using this same method of course!)
5819
+ *
5820
+ * After the close method completes there should be no MongoClient related resources [ref-ed in Node.js' event loop](https://docs.libuv.org/en/v1.x/handle.html#reference-counting).
5821
+ * This should allow Node.js to exit gracefully if MongoClient resources were the only active handles in the event loop.
5822
+ *
5823
+ * @param _force - currently an unused flag that has no effect. Defaults to `false`.
5824
+ */
5825
+ close(_force?: boolean): Promise<void>;
5757
5826
  private _close;
5758
5827
  /**
5759
5828
  * Create a new Db instance sharing the current socket connections.
@@ -5946,6 +6015,29 @@ export declare class MongoClientBulkWriteExecutionError extends MongoRuntimeErro
5946
6015
  get name(): string;
5947
6016
  }
5948
6017
 
6018
+ /**
6019
+ * An error generated when the MongoClient is closed and async
6020
+ * operations are interrupted.
6021
+ *
6022
+ * @public
6023
+ * @category Error
6024
+ */
6025
+ export declare class MongoClientClosedError extends MongoAPIError {
6026
+ /**
6027
+ * **Do not use this constructor!**
6028
+ *
6029
+ * Meant for internal use only.
6030
+ *
6031
+ * @remarks
6032
+ * This class is only meant to be constructed within the driver. This constructor is
6033
+ * not subject to semantic versioning compatibility guarantees and may change at any time.
6034
+ *
6035
+ * @public
6036
+ **/
6037
+ constructor();
6038
+ get name(): string;
6039
+ }
6040
+
5949
6041
  /** @public */
5950
6042
  export declare type MongoClientEvents = Pick<TopologyEvents, (typeof MONGO_CLIENT_EVENTS)[number]> & {
5951
6043
  open(mongoClient: MongoClient): void;
@@ -6396,14 +6488,14 @@ export declare interface MongoDBLogWritable {
6396
6488
  /** @public */
6397
6489
  export declare class MongoDBNamespace {
6398
6490
  db: string;
6399
- collection?: string | undefined;
6491
+ collection?: string;
6400
6492
  /**
6401
6493
  * Create a namespace object
6402
6494
  *
6403
6495
  * @param db - database name
6404
6496
  * @param collection - collection name
6405
6497
  */
6406
- constructor(db: string, collection?: string | undefined);
6498
+ constructor(db: string, collection?: string);
6407
6499
  toString(): string;
6408
6500
  withCollection(collection: string): MongoDBCollectionNamespace;
6409
6501
  static fromString(namespace?: string): MongoDBNamespace;
@@ -7345,6 +7437,8 @@ export declare interface OIDCCallbackParams {
7345
7437
  idpInfo?: IdPInfo;
7346
7438
  /** The refresh token, if applicable, to be used by the callback to request a new token from the issuer. */
7347
7439
  refreshToken?: string;
7440
+ /** The token audience for GCP and Azure. */
7441
+ tokenAudience?: string;
7348
7442
  }
7349
7443
 
7350
7444
  /**
@@ -7373,6 +7467,8 @@ export declare type OnlyFieldsOfType<TSchema, FieldType = any, AssignableType =
7373
7467
 
7374
7468
  /* Excluded from this release type: OpCompressedRequest */
7375
7469
 
7470
+ /* Excluded from this release type: OpCompressesRequestOptions */
7471
+
7376
7472
  /** @public */
7377
7473
  export declare interface OperationOptions extends BSONSerializeOptions {
7378
7474
  /** Specify ClientSession for this command */
@@ -7678,7 +7774,7 @@ export declare interface RenameOptions extends CommandOperationOptions {
7678
7774
 
7679
7775
  /** @public */
7680
7776
  export declare interface ReplaceOneModel<TSchema extends Document = Document> {
7681
- /** The filter to limit the replaced document. */
7777
+ /** The filter that specifies which document to replace. In the case of multiple matches, the first document matched is replaced. */
7682
7778
  filter: Filter<TSchema>;
7683
7779
  /** The document with which to replace the matched document. */
7684
7780
  replacement: WithoutId<TSchema>;
@@ -7688,6 +7784,8 @@ export declare interface ReplaceOneModel<TSchema extends Document = Document> {
7688
7784
  hint?: Hint;
7689
7785
  /** When true, creates a new document if no document matches the query. */
7690
7786
  upsert?: boolean;
7787
+ /** Specifies the sort order for the documents matched by the filter. */
7788
+ sort?: Sort;
7691
7789
  }
7692
7790
 
7693
7791
  /** @public */
@@ -7702,6 +7800,8 @@ export declare interface ReplaceOptions extends CommandOperationOptions {
7702
7800
  upsert?: boolean;
7703
7801
  /** Map of parameter names and values that can be accessed using $$var (requires MongoDB 5.0). */
7704
7802
  let?: Document;
7803
+ /** Specifies the sort order for the documents matched by the filter. */
7804
+ sort?: Sort;
7705
7805
  }
7706
7806
 
7707
7807
  /**
@@ -8214,19 +8314,24 @@ export declare type SeverityLevel = (typeof SeverityLevel)[keyof typeof Severity
8214
8314
 
8215
8315
  /** @public */
8216
8316
  export declare type Sort = string | Exclude<SortDirection, {
8217
- $meta: string;
8218
- }> | string[] | {
8219
- [key: string]: SortDirection;
8220
- } | Map<string, SortDirection> | [string, SortDirection][] | [string, SortDirection];
8317
+ readonly $meta: string;
8318
+ }> | ReadonlyArray<string> | {
8319
+ readonly [key: string]: SortDirection;
8320
+ } | ReadonlyMap<string, SortDirection> | ReadonlyArray<readonly [string, SortDirection]> | readonly [string, SortDirection];
8221
8321
 
8222
8322
  /** @public */
8223
8323
  export declare type SortDirection = 1 | -1 | 'asc' | 'desc' | 'ascending' | 'descending' | {
8224
- $meta: string;
8324
+ readonly $meta: string;
8225
8325
  };
8226
8326
 
8227
- /* Excluded from this release type: SortDirectionForCmd */
8327
+ /** Below stricter types were created for sort that correspond with type that the cmd takes */
8328
+ /** @public */
8329
+ export declare type SortDirectionForCmd = 1 | -1 | {
8330
+ $meta: string;
8331
+ };
8228
8332
 
8229
- /* Excluded from this release type: SortForCmd */
8333
+ /** @public */
8334
+ export declare type SortForCmd = Map<string, SortDirectionForCmd>;
8230
8335
 
8231
8336
  /* Excluded from this release type: SrvPoller */
8232
8337
 
@@ -8327,6 +8432,8 @@ export declare type SupportedNodeConnectionOptions = SupportedTLSConnectionOptio
8327
8432
  export declare type SupportedSocketOptions = Pick<TcpNetConnectOpts & {
8328
8433
  autoSelectFamily?: boolean;
8329
8434
  autoSelectFamilyAttemptTimeout?: number;
8435
+ /** Node.JS socket option to set the time the first keepalive probe is sent on an idle socket. Defaults to 120000ms */
8436
+ keepAliveInitialDelay?: number;
8330
8437
  }, (typeof LEGAL_TCP_SOCKET_OPTIONS)[number]>;
8331
8438
 
8332
8439
  /** @public */
@@ -8694,7 +8801,7 @@ export declare interface UpdateManyModel<TSchema extends Document = Document> {
8694
8801
 
8695
8802
  /** @public */
8696
8803
  export declare interface UpdateOneModel<TSchema extends Document = Document> {
8697
- /** The filter to limit the updated documents. */
8804
+ /** The filter that specifies which document to update. In the case of multiple matches, the first document matched is updated. */
8698
8805
  filter: Filter<TSchema>;
8699
8806
  /**
8700
8807
  * The modifications to apply. The value can be either:
@@ -8710,6 +8817,8 @@ export declare interface UpdateOneModel<TSchema extends Document = Document> {
8710
8817
  hint?: Hint;
8711
8818
  /** When true, creates a new document if no document matches the query. */
8712
8819
  upsert?: boolean;
8820
+ /** Specifies the sort order for the documents matched by the filter. */
8821
+ sort?: Sort;
8713
8822
  }
8714
8823
 
8715
8824
  /** @public */
@@ -8761,6 +8870,8 @@ export declare interface UpdateStatement {
8761
8870
  arrayFilters?: Document[];
8762
8871
  /** A document or string that specifies the index to use to support the query predicate. */
8763
8872
  hint?: Hint;
8873
+ /** Specifies the sort order for the documents matched by the filter. */
8874
+ sort?: SortForCmd;
8764
8875
  }
8765
8876
 
8766
8877
  export { UUID }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mongodb",
3
- "version": "6.16.0",
3
+ "version": "6.17.0-dev.20250605.sha.57ef31be",
4
4
  "description": "The official MongoDB driver for Node.js",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -26,7 +26,7 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "@mongodb-js/saslprep": "^1.1.9",
29
- "bson": "^6.10.3",
29
+ "bson": "^6.10.4",
30
30
  "mongodb-connection-string-url": "^3.0.0"
31
31
  },
32
32
  "peerDependencies": {
@@ -65,50 +65,50 @@
65
65
  "@aws-sdk/credential-providers": "^3.632.0",
66
66
  "@iarna/toml": "^2.2.5",
67
67
  "@istanbuljs/nyc-config-typescript": "^1.0.2",
68
- "@microsoft/api-extractor": "^7.49.2",
68
+ "@microsoft/api-extractor": "^7.52.5",
69
69
  "@microsoft/tsdoc-config": "^0.17.1",
70
- "@mongodb-js/zstd": "^2.0.0",
70
+ "@mongodb-js/zstd": "^2.0.1",
71
71
  "@types/chai": "^4.3.17",
72
72
  "@types/chai-subset": "^1.3.5",
73
- "@types/express": "^4.17.21",
73
+ "@types/express": "^5.0.1",
74
74
  "@types/kerberos": "^1.1.5",
75
75
  "@types/mocha": "^10.0.9",
76
- "@types/node": "^22.13.0",
76
+ "@types/node": "^22.15.3",
77
77
  "@types/saslprep": "^1.0.3",
78
- "@types/semver": "^7.5.8",
79
- "@types/sinon": "^17.0.3",
80
- "@types/sinon-chai": "^3.2.12",
81
- "@types/whatwg-url": "^11.0.5",
82
- "@typescript-eslint/eslint-plugin": "8.4.0",
83
- "@typescript-eslint/parser": "8.4.0",
78
+ "@types/semver": "^7.7.0",
79
+ "@types/sinon": "^17.0.4",
80
+ "@types/sinon-chai": "^4.0.0",
81
+ "@types/whatwg-url": "^13.0.0",
82
+ "@typescript-eslint/eslint-plugin": "^8.31.1",
83
+ "@typescript-eslint/parser": "^8.31.1",
84
84
  "chai": "^4.4.1",
85
85
  "chai-subset": "^1.6.0",
86
86
  "chalk": "^4.1.2",
87
- "eslint": "9.9.0",
88
- "eslint-config-prettier": "^9.1.0",
87
+ "eslint": "^9.25.1",
88
+ "eslint-config-prettier": "^10.1.2",
89
89
  "eslint-plugin-mocha": "^10.4.1",
90
90
  "eslint-plugin-prettier": "^5.2.3",
91
91
  "eslint-plugin-simple-import-sort": "^12.1.1",
92
92
  "eslint-plugin-tsdoc": "^0.4.0",
93
93
  "eslint-plugin-unused-imports": "^4.1.4",
94
- "express": "^4.21.2",
94
+ "express": "^5.1.0",
95
95
  "gcp-metadata": "^5.3.0",
96
96
  "js-yaml": "^4.1.0",
97
97
  "mocha": "^10.8.2",
98
98
  "mocha-sinon": "^2.1.2",
99
- "mongodb-client-encryption": "^6.3.0",
99
+ "mongodb-client-encryption": "^6.4.0",
100
100
  "mongodb-legacy": "^6.1.3",
101
101
  "nyc": "^15.1.0",
102
- "prettier": "^3.4.2",
102
+ "prettier": "^3.5.3",
103
103
  "semver": "^7.7.0",
104
- "sinon": "^18.0.0",
104
+ "sinon": "^18.0.1",
105
105
  "sinon-chai": "^3.7.0",
106
106
  "snappy": "^7.2.2",
107
107
  "socks": "^2.8.1",
108
108
  "source-map-support": "^0.5.21",
109
109
  "ts-node": "^10.9.2",
110
- "tsd": "^0.31.2",
111
- "typescript": "5.5",
110
+ "tsd": "^0.32.0",
111
+ "typescript": "5.8.3",
112
112
  "typescript-cached-transpile": "^0.0.6",
113
113
  "v8-heapsnapshot": "^1.3.1",
114
114
  "yargs": "^17.7.2"
@@ -175,4 +175,4 @@
175
175
  "moduleResolution": "node"
176
176
  }
177
177
  }
178
- }
178
+ }