@mongosh/shell-api 3.18.0 → 3.20.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.
package/lib/api-raw.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  /// <reference types="node" />
2
2
 
3
3
  import type { Agent } from 'https';
4
+ import type { AgentConnectOpts } from 'agent-base';
4
5
  import { Binary } from 'bson';
5
6
  import { BSONRegExp } from 'bson';
6
7
  import { BSONSymbol } from 'bson';
@@ -26,6 +27,7 @@ import { ObjectId } from 'bson';
26
27
  import type { ObjectIdLike } from 'bson';
27
28
  import { Readable } from 'stream';
28
29
  import type { RequestOptions } from 'https';
30
+ import type { SecureContextOptions } from 'tls';
29
31
  import type { SerializeOptions } from 'bson';
30
32
  import type { ServerResponse } from 'http';
31
33
  import type { SrvRecord } from 'dns';
@@ -879,6 +881,10 @@ declare interface AutoEncryptionOptions {
879
881
  bypassAutoEncryption?: boolean;
880
882
  /** Allows users to bypass query analysis */
881
883
  bypassQueryAnalysis?: boolean;
884
+ /**
885
+ * Sets the expiration time for the DEK in the cache in milliseconds. Defaults to 60000. 0 means no timeout.
886
+ */
887
+ keyExpirationMS?: number;
882
888
  options?: {
883
889
  /** An optional hook to catch logging messages from the underlying encryption engine */
884
890
  logger?: (level: AutoEncryptionLoggerLevel, message: string) => void;
@@ -1165,10 +1171,10 @@ declare class BulkFindOp extends ShellApiWithMongoClass {
1165
1171
 
1166
1172
  /** @public */
1167
1173
  declare abstract class BulkOperationBase {
1168
- private collection;
1169
1174
  isOrdered: boolean;
1170
1175
  /* Excluded from this release type: s */
1171
1176
  operationId?: number;
1177
+ private collection;
1172
1178
  /* Excluded from this release type: __constructor */
1173
1179
  /**
1174
1180
  * Add a single insert document to the bulk operation
@@ -1301,7 +1307,7 @@ declare class BulkWriteResult {
1301
1307
  getRawResponse(): Document_2;
1302
1308
  /** Returns true if the bulk operation contains a write error */
1303
1309
  hasWriteErrors(): boolean;
1304
- /** Returns the number of write errors off the bulk operation */
1310
+ /** Returns the number of write errors from the bulk operation */
1305
1311
  getWriteErrorCount(): number;
1306
1312
  /** Returns a specific write error object */
1307
1313
  getWriteErrorAt(index: number): WriteError | undefined;
@@ -1339,7 +1345,10 @@ declare type CacheOptions = {
1339
1345
  aggregationSchemaTTL: number;
1340
1346
  };
1341
1347
 
1342
- /** @public */
1348
+ /**
1349
+ * @public
1350
+ * @deprecated Will be removed in favor of `AbortSignal` in the next major release.
1351
+ */
1343
1352
  declare class CancellationToken extends TypedEventEmitter<{
1344
1353
  cancel(): void;
1345
1354
  }> {
@@ -1447,7 +1456,7 @@ declare class ChangeStream<TSchema extends Document_2 = Document_2, TChange exte
1447
1456
  * @public
1448
1457
  * @see https://www.mongodb.com/docs/manual/reference/change-events/modify/#mongodb-data-modify
1449
1458
  */
1450
- declare interface ChangeStreamCollModDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID {
1459
+ declare interface ChangeStreamCollModDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID, ChangeStreamDocumentWallTime {
1451
1460
  /** Describes the type of operation represented in this change notification */
1452
1461
  operationType: 'modify';
1453
1462
  }
@@ -1456,7 +1465,7 @@ declare interface ChangeStreamCollModDocument extends ChangeStreamDocumentCommon
1456
1465
  * @public
1457
1466
  * @see https://www.mongodb.com/docs/manual/reference/change-events/create/#mongodb-data-create
1458
1467
  */
1459
- declare interface ChangeStreamCreateDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID {
1468
+ declare interface ChangeStreamCreateDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID, ChangeStreamDocumentWallTime {
1460
1469
  /** Describes the type of operation represented in this change notification */
1461
1470
  operationType: 'create';
1462
1471
  /**
@@ -1472,7 +1481,7 @@ declare interface ChangeStreamCreateDocument extends ChangeStreamDocumentCommon,
1472
1481
  * @public
1473
1482
  * @see https://www.mongodb.com/docs/manual/reference/change-events/createIndexes/#mongodb-data-createIndexes
1474
1483
  */
1475
- declare interface ChangeStreamCreateIndexDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID, ChangeStreamDocumentOperationDescription {
1484
+ declare interface ChangeStreamCreateIndexDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID, ChangeStreamDocumentOperationDescription, ChangeStreamDocumentWallTime {
1476
1485
  /** Describes the type of operation represented in this change notification */
1477
1486
  operationType: 'createIndexes';
1478
1487
  }
@@ -1505,7 +1514,7 @@ declare class ChangeStreamCursor extends ShellApiWithMongoClass {
1505
1514
  * @public
1506
1515
  * @see https://www.mongodb.com/docs/manual/reference/change-events/#delete-event
1507
1516
  */
1508
- declare interface ChangeStreamDeleteDocument<TSchema extends Document_2 = Document_2> extends ChangeStreamDocumentCommon, ChangeStreamDocumentKey<TSchema>, ChangeStreamDocumentCollectionUUID {
1517
+ declare interface ChangeStreamDeleteDocument<TSchema extends Document_2 = Document_2> extends ChangeStreamDocumentCommon, ChangeStreamDocumentKey<TSchema>, ChangeStreamDocumentCollectionUUID, ChangeStreamDocumentWallTime {
1509
1518
  /** Describes the type of operation represented in this change notification */
1510
1519
  operationType: 'delete';
1511
1520
  /** Namespace the delete event occurred on */
@@ -1598,11 +1607,21 @@ declare interface ChangeStreamDocumentOperationDescription {
1598
1607
  operationDescription?: Document_2;
1599
1608
  }
1600
1609
 
1610
+ /** @public */
1611
+ declare interface ChangeStreamDocumentWallTime {
1612
+ /**
1613
+ * The server date and time of the database operation.
1614
+ * wallTime differs from clusterTime in that clusterTime is a timestamp taken from the oplog entry associated with the database operation event.
1615
+ * @sinceServerVersion 6.0.0
1616
+ */
1617
+ wallTime?: Date;
1618
+ }
1619
+
1601
1620
  /**
1602
1621
  * @public
1603
1622
  * @see https://www.mongodb.com/docs/manual/reference/change-events/#dropdatabase-event
1604
1623
  */
1605
- declare interface ChangeStreamDropDatabaseDocument extends ChangeStreamDocumentCommon {
1624
+ declare interface ChangeStreamDropDatabaseDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentWallTime {
1606
1625
  /** Describes the type of operation represented in this change notification */
1607
1626
  operationType: 'dropDatabase';
1608
1627
  /** The database dropped */
@@ -1615,7 +1634,7 @@ declare interface ChangeStreamDropDatabaseDocument extends ChangeStreamDocumentC
1615
1634
  * @public
1616
1635
  * @see https://www.mongodb.com/docs/manual/reference/change-events/#drop-event
1617
1636
  */
1618
- declare interface ChangeStreamDropDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID {
1637
+ declare interface ChangeStreamDropDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID, ChangeStreamDocumentWallTime {
1619
1638
  /** Describes the type of operation represented in this change notification */
1620
1639
  operationType: 'drop';
1621
1640
  /** Namespace the drop event occurred on */
@@ -1627,7 +1646,7 @@ declare interface ChangeStreamDropDocument extends ChangeStreamDocumentCommon, C
1627
1646
  * @public
1628
1647
  * @see https://www.mongodb.com/docs/manual/reference/change-events/dropIndexes/#mongodb-data-dropIndexes
1629
1648
  */
1630
- declare interface ChangeStreamDropIndexDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID, ChangeStreamDocumentOperationDescription {
1649
+ declare interface ChangeStreamDropIndexDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID, ChangeStreamDocumentOperationDescription, ChangeStreamDocumentWallTime {
1631
1650
  /** Describes the type of operation represented in this change notification */
1632
1651
  operationType: 'dropIndexes';
1633
1652
  }
@@ -1654,7 +1673,7 @@ declare type ChangeStreamEvents<TSchema extends Document_2 = Document_2, TChange
1654
1673
  * @public
1655
1674
  * @see https://www.mongodb.com/docs/manual/reference/change-events/#insert-event
1656
1675
  */
1657
- declare interface ChangeStreamInsertDocument<TSchema extends Document_2 = Document_2> extends ChangeStreamDocumentCommon, ChangeStreamDocumentKey<TSchema>, ChangeStreamDocumentCollectionUUID {
1676
+ declare interface ChangeStreamInsertDocument<TSchema extends Document_2 = Document_2> extends ChangeStreamDocumentCommon, ChangeStreamDocumentKey<TSchema>, ChangeStreamDocumentCollectionUUID, ChangeStreamDocumentWallTime {
1658
1677
  /** Describes the type of operation represented in this change notification */
1659
1678
  operationType: 'insert';
1660
1679
  /** This key will contain the document being inserted */
@@ -1667,7 +1686,7 @@ declare interface ChangeStreamInsertDocument<TSchema extends Document_2 = Docume
1667
1686
  * @public
1668
1687
  * @see https://www.mongodb.com/docs/manual/reference/change-events/#invalidate-event
1669
1688
  */
1670
- declare interface ChangeStreamInvalidateDocument extends ChangeStreamDocumentCommon {
1689
+ declare interface ChangeStreamInvalidateDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentWallTime {
1671
1690
  /** Describes the type of operation represented in this change notification */
1672
1691
  operationType: 'invalidate';
1673
1692
  }
@@ -1758,7 +1777,7 @@ declare interface ChangeStreamRefineCollectionShardKeyDocument extends ChangeStr
1758
1777
  * @public
1759
1778
  * @see https://www.mongodb.com/docs/manual/reference/change-events/#rename-event
1760
1779
  */
1761
- declare interface ChangeStreamRenameDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID {
1780
+ declare interface ChangeStreamRenameDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID, ChangeStreamDocumentWallTime {
1762
1781
  /** Describes the type of operation represented in this change notification */
1763
1782
  operationType: 'rename';
1764
1783
  /** The new name for the `ns.coll` collection */
@@ -1774,7 +1793,7 @@ declare interface ChangeStreamRenameDocument extends ChangeStreamDocumentCommon,
1774
1793
  * @public
1775
1794
  * @see https://www.mongodb.com/docs/manual/reference/change-events/#replace-event
1776
1795
  */
1777
- declare interface ChangeStreamReplaceDocument<TSchema extends Document_2 = Document_2> extends ChangeStreamDocumentCommon, ChangeStreamDocumentKey<TSchema> {
1796
+ declare interface ChangeStreamReplaceDocument<TSchema extends Document_2 = Document_2> extends ChangeStreamDocumentCommon, ChangeStreamDocumentKey<TSchema>, ChangeStreamDocumentWallTime {
1778
1797
  /** Describes the type of operation represented in this change notification */
1779
1798
  operationType: 'replace';
1780
1799
  /** The fullDocument of a replace event represents the document after the insert of the replacement document */
@@ -1804,7 +1823,7 @@ declare interface ChangeStreamReshardCollectionDocument extends ChangeStreamDocu
1804
1823
  * @public
1805
1824
  * @see https://www.mongodb.com/docs/manual/reference/change-events/shardCollection/#mongodb-data-shardCollection
1806
1825
  */
1807
- declare interface ChangeStreamShardCollectionDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID, ChangeStreamDocumentOperationDescription {
1826
+ declare interface ChangeStreamShardCollectionDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID, ChangeStreamDocumentOperationDescription, ChangeStreamDocumentWallTime {
1808
1827
  /** Describes the type of operation represented in this change notification */
1809
1828
  operationType: 'shardCollection';
1810
1829
  }
@@ -1821,7 +1840,7 @@ declare interface ChangeStreamSplitEvent {
1821
1840
  * @public
1822
1841
  * @see https://www.mongodb.com/docs/manual/reference/change-events/#update-event
1823
1842
  */
1824
- declare interface ChangeStreamUpdateDocument<TSchema extends Document_2 = Document_2> extends ChangeStreamDocumentCommon, ChangeStreamDocumentKey<TSchema>, ChangeStreamDocumentCollectionUUID {
1843
+ declare interface ChangeStreamUpdateDocument<TSchema extends Document_2 = Document_2> extends ChangeStreamDocumentCommon, ChangeStreamDocumentKey<TSchema>, ChangeStreamDocumentCollectionUUID, ChangeStreamDocumentWallTime {
1825
1844
  /** Describes the type of operation represented in this change notification */
1826
1845
  operationType: 'update';
1827
1846
  /**
@@ -2405,6 +2424,10 @@ declare interface ClientEncryptionOptions {
2405
2424
  * TLS options for kms providers to use.
2406
2425
  */
2407
2426
  tlsOptions?: CSFLEKMSTlsOptions;
2427
+ /**
2428
+ * Sets the expiration time for the DEK in the cache in milliseconds. Defaults to 60000. 0 means no timeout.
2429
+ */
2430
+ keyExpirationMS?: number;
2408
2431
  /**
2409
2432
  * @experimental
2410
2433
  *
@@ -2483,6 +2506,7 @@ declare type ClientInsertResult = {
2483
2506
 
2484
2507
  /**
2485
2508
  * @public
2509
+ * @deprecated This interface will be made internal in the next major release.
2486
2510
  * @see https://github.com/mongodb/specifications/blob/master/source/mongodb-handshake/handshake.md#hello-command
2487
2511
  */
2488
2512
  declare interface ClientMetadata {
@@ -2526,6 +2550,8 @@ declare interface ClientReplaceOneModel<TSchema> extends ClientWriteModel {
2526
2550
  hint?: Hint;
2527
2551
  /** When true, creates a new document if no document matches the query. */
2528
2552
  upsert?: boolean;
2553
+ /** Specifies the sort order for the documents matched by the filter. */
2554
+ sort?: Sort;
2529
2555
  }
2530
2556
 
2531
2557
  /**
@@ -2547,6 +2573,7 @@ declare class ClientSession extends TypedEventEmitter<ClientSessionEvents> imple
2547
2573
  explicit: boolean;
2548
2574
  /* Excluded from this release type: owner */
2549
2575
  defaultTransactionOptions: TransactionOptions;
2576
+ /** @deprecated - Will be made internal in the next major release */
2550
2577
  transaction: Transaction;
2551
2578
  /* Excluded from this release type: commitAttempted */
2552
2579
  readonly snapshotEnabled: boolean;
@@ -2772,6 +2799,8 @@ declare interface ClientUpdateOneModel<TSchema> extends ClientWriteModel {
2772
2799
  hint?: Hint;
2773
2800
  /** When true, creates a new document if no document matches the query. */
2774
2801
  upsert?: boolean;
2802
+ /** Specifies the sort order for the documents matched by the filter. */
2803
+ sort?: Sort;
2775
2804
  }
2776
2805
 
2777
2806
  /** @public */
@@ -2819,7 +2848,7 @@ declare interface ClientWriteModel {
2819
2848
  }
2820
2849
 
2821
2850
  declare interface Closable {
2822
- close(force: boolean): Promise<void>;
2851
+ close(): Promise<void>;
2823
2852
  suspend(): Promise<() => Promise<void>>;
2824
2853
  }
2825
2854
 
@@ -2901,7 +2930,9 @@ declare class Collection<M extends GenericServerSideSchema = GenericServerSideSc
2901
2930
  multi?: boolean;
2902
2931
  }): Promise<UpdateResult_2 | Document_2>;
2903
2932
  updateMany(filter: Document_2, update: Document_2, options?: UpdateOptions): Promise<UpdateResult_2 | Document_2>;
2904
- updateOne(filter: Document_2, update: Document_2, options?: UpdateOptions): Promise<UpdateResult_2 | Document_2>;
2933
+ updateOne(filter: Document_2, update: Document_2, options?: UpdateOptions & {
2934
+ sort?: Document_2;
2935
+ }): Promise<UpdateResult_2 | Document_2>;
2905
2936
  compactStructuredEncryptionData(): Promise<Document_2>;
2906
2937
  convertToCapped(size: number): Promise<Document_2>;
2907
2938
  _createIndexes(keyPatterns: Document_2[], options?: CreateIndexesOptions, commitQuorum?: number | string): Promise<string[]>;
@@ -3075,7 +3106,9 @@ declare class Collection_2<TSchema extends Document_2 = Document_2> {
3075
3106
  * @param update - The modifications to apply
3076
3107
  * @param options - Optional settings for the command
3077
3108
  */
3078
- updateOne(filter: Filter<TSchema>, update: UpdateFilter<TSchema> | Document_2[], options?: UpdateOptions): Promise<UpdateResult<TSchema>>;
3109
+ updateOne(filter: Filter<TSchema>, update: UpdateFilter<TSchema> | Document_2[], options?: UpdateOptions & {
3110
+ sort?: Sort;
3111
+ }): Promise<UpdateResult<TSchema>>;
3079
3112
  /**
3080
3113
  * Replace a document in a collection with another document
3081
3114
  *
@@ -3617,6 +3650,7 @@ declare class CommandFailedEvent {
3617
3650
  commandName: string;
3618
3651
  failure: Error;
3619
3652
  serviceId?: ObjectId;
3653
+ databaseName: string;
3620
3654
  /* Excluded from this release type: name */
3621
3655
  /* Excluded from this release type: __constructor */
3622
3656
  get hasServiceId(): boolean;
@@ -3645,6 +3679,10 @@ declare interface CommandOperationOptions extends OperationOptions, WriteConcern
3645
3679
  retryWrites?: boolean;
3646
3680
  dbName?: string;
3647
3681
  authdb?: string;
3682
+ /**
3683
+ * @deprecated
3684
+ * This option is deprecated and will be removed in an upcoming major version.
3685
+ */
3648
3686
  noResponse?: boolean;
3649
3687
  }
3650
3688
 
@@ -3701,6 +3739,7 @@ declare class CommandSucceededEvent {
3701
3739
  commandName: string;
3702
3740
  reply: unknown;
3703
3741
  serviceId?: ObjectId;
3742
+ databaseName: string;
3704
3743
  /* Excluded from this release type: name */
3705
3744
  /* Excluded from this release type: __constructor */
3706
3745
  get hasServiceId(): boolean;
@@ -4870,7 +4909,7 @@ declare class DevtoolsConnectionState {
4870
4909
  productName: string;
4871
4910
  private stateShareClient;
4872
4911
  private stateShareServer;
4873
- constructor(options: Pick<DevtoolsConnectOptions, 'productDocsLink' | 'productName' | 'oidc' | 'parentHandle'>, logger: ConnectLogEmitter, ca: string | undefined);
4912
+ constructor(options: Pick<DevtoolsConnectOptions, 'productDocsLink' | 'productName' | 'oidc' | 'parentHandle'>, logger: ConnectLogEmitter);
4874
4913
  getStateShareServer(): Promise<string>;
4875
4914
  destroy(): Promise<void>;
4876
4915
  }
@@ -4882,7 +4921,7 @@ declare interface DevtoolsConnectOptions extends MongoClientOptions {
4882
4921
  parentState?: DevtoolsConnectionState;
4883
4922
  parentHandle?: string;
4884
4923
  proxy?: DevtoolsProxyOptions | AgentWithInitialize;
4885
- applyProxyToOIDC?: boolean;
4924
+ applyProxyToOIDC?: boolean | DevtoolsProxyOptions | AgentWithInitialize;
4886
4925
  }
4887
4926
 
4888
4927
  declare interface DevtoolsProxyOptions {
@@ -4894,6 +4933,7 @@ declare interface DevtoolsProxyOptions {
4894
4933
  identityKeyPassphrase?: string;
4895
4934
  };
4896
4935
  ca?: ConnectionOptions['ca'];
4936
+ caExcludeSystemCerts?: boolean;
4897
4937
  env?: Record<string, string | undefined>;
4898
4938
  }
4899
4939
 
@@ -5680,7 +5720,10 @@ declare type HostInformation = {
5680
5720
  is_do_url?: boolean;
5681
5721
  };
5682
5722
 
5683
- /** @public */
5723
+ /**
5724
+ * @public
5725
+ * @deprecated Use a custom `fetch` function instead
5726
+ */
5684
5727
  declare type HttpOptions = Partial<Pick<RequestOptions, 'agent' | 'ca' | 'cert' | 'crl' | 'headers' | 'key' | 'lookup' | 'passphrase' | 'pfx' | 'timeout'>>;
5685
5728
 
5686
5729
  /**
@@ -6186,7 +6229,7 @@ declare interface KMSProviders {
6186
6229
  }
6187
6230
 
6188
6231
  /** @public */
6189
- declare const LEGAL_TCP_SOCKET_OPTIONS: readonly ["autoSelectFamily", "autoSelectFamilyAttemptTimeout", "family", "hints", "localAddress", "localPort", "lookup"];
6232
+ declare const LEGAL_TCP_SOCKET_OPTIONS: readonly ["autoSelectFamily", "autoSelectFamilyAttemptTimeout", "keepAliveInitialDelay", "family", "hints", "localAddress", "localPort", "lookup"];
6190
6233
 
6191
6234
  /** @public */
6192
6235
  declare const LEGAL_TLS_SOCKET_OPTIONS: readonly ["allowPartialTrustChain", "ALPNProtocols", "ca", "cert", "checkServerIdentity", "ciphers", "crl", "ecdhCurve", "key", "minDHSize", "passphrase", "pfx", "rejectUnauthorized", "secureContext", "secureProtocol", "servername", "session"];
@@ -6358,7 +6401,7 @@ export declare class Mongo<M extends GenericServerSideSchema = GenericServerSide
6358
6401
  bulkWrite(models: AnyClientBulkWriteModel<Document_2>[], options?: ClientBulkWriteOptions): Promise<ClientBulkWriteResult_2>;
6359
6402
  getDBNames(options?: ListDatabasesOptions): Promise<StringKey<M>[]>;
6360
6403
  show(cmd: string, arg?: string, tracked?: boolean): Promise<CommandResult>;
6361
- close(force?: boolean): Promise<void>;
6404
+ close(): Promise<void>;
6362
6405
  _suspend(): Promise<() => Promise<void>>;
6363
6406
  getReadPrefMode(): ReadPreferenceMode;
6364
6407
  getReadPrefTagSet(): Record<string, string>[] | undefined;
@@ -6387,22 +6430,35 @@ export declare class Mongo<M extends GenericServerSideSchema = GenericServerSide
6387
6430
  declare const MONGO_CLIENT_EVENTS: readonly ["connectionPoolCreated", "connectionPoolReady", "connectionPoolCleared", "connectionPoolClosed", "connectionCreated", "connectionReady", "connectionClosed", "connectionCheckOutStarted", "connectionCheckOutFailed", "connectionCheckedOut", "connectionCheckedIn", "commandStarted", "commandSucceeded", "commandFailed", "serverOpening", "serverClosed", "serverDescriptionChanged", "topologyOpening", "topologyClosed", "topologyDescriptionChanged", "error", "timeout", "close", "serverHeartbeatStarted", "serverHeartbeatSucceeded", "serverHeartbeatFailed"];
6388
6431
 
6389
6432
  /**
6390
- * The **MongoClient** class is a class that allows for making Connections to MongoDB.
6391
6433
  * @public
6392
6434
  *
6435
+ * The **MongoClient** class is a class that allows for making Connections to MongoDB.
6436
+ *
6437
+ * **NOTE:** The programmatically provided options take precedence over the URI options.
6438
+ *
6393
6439
  * @remarks
6394
- * The programmatically provided options take precedence over the URI options.
6440
+ *
6441
+ * A MongoClient is the entry point to connecting to a MongoDB server.
6442
+ *
6443
+ * It handles a multitude of features on your application's behalf:
6444
+ * - **Server Host Connection Configuration**: A MongoClient is responsible for reading TLS cert, ca, and crl files if provided.
6445
+ * - **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.
6446
+ * - **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.
6447
+ * - **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.
6448
+ * - **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.
6449
+ * - **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.
6450
+ * - **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.
6451
+ *
6452
+ * There are many more features of a MongoClient that are not listed above.
6453
+ *
6454
+ * In order to enable these features, a number of asynchronous Node.js resources are established by the driver: Timers, FS Requests, Sockets, etc.
6455
+ * For details on cleanup, please refer to the MongoClient `close()` documentation.
6395
6456
  *
6396
6457
  * @example
6397
6458
  * ```ts
6398
6459
  * import { MongoClient } from 'mongodb';
6399
- *
6400
6460
  * // Enable command monitoring for debugging
6401
- * const client = new MongoClient('mongodb://localhost:27017', { monitorCommands: true });
6402
- *
6403
- * client.on('commandStarted', started => console.log(started));
6404
- * client.db().collection('pets');
6405
- * await client.insertOne({ name: 'spot', kind: 'dog' });
6461
+ * const client = new MongoClient('mongodb://localhost:27017?appName=mflix', { monitorCommands: true });
6406
6462
  * ```
6407
6463
  */
6408
6464
  declare class MongoClient extends TypedEventEmitter<MongoClientEvents> implements AsyncDisposable_2 {
@@ -6414,10 +6470,15 @@ declare class MongoClient extends TypedEventEmitter<MongoClientEvents> implement
6414
6470
  /**
6415
6471
  * The consolidate, parsed, transformed and merged options.
6416
6472
  */
6417
- readonly options: Readonly<Omit<MongoOptions, 'monitorCommands' | 'ca' | 'crl' | 'key' | 'cert'>> & Pick<MongoOptions, 'monitorCommands' | 'ca' | 'crl' | 'key' | 'cert'>;
6473
+ readonly options: Readonly<Omit<MongoOptions, 'monitorCommands' | 'ca' | 'crl' | 'key' | 'cert' | 'driverInfo' | 'additionalDriverInfo' | 'metadata' | 'extendedMetadata'>> & Pick<MongoOptions, 'monitorCommands' | 'ca' | 'crl' | 'key' | 'cert' | 'driverInfo' | 'additionalDriverInfo' | 'metadata' | 'extendedMetadata'>;
6418
6474
  constructor(url: string, options?: MongoClientOptions);
6419
6475
  /* Excluded from this release type: [Symbol.asyncDispose] */
6420
6476
  /* Excluded from this release type: asyncDispose */
6477
+ /**
6478
+ * Append metadata to the client metadata after instantiation.
6479
+ * @param driverInfo - Information about the application or library.
6480
+ */
6481
+ appendMetadata(driverInfo: DriverInfo): void;
6421
6482
  /* Excluded from this release type: checkForNonGenuineHosts */
6422
6483
  get serverApi(): Readonly<ServerApi | undefined>;
6423
6484
  /* Excluded from this release type: monitorCommands */
@@ -6454,19 +6515,51 @@ declare class MongoClient extends TypedEventEmitter<MongoClientEvents> implement
6454
6515
  connect(): Promise<this>;
6455
6516
  /* Excluded from this release type: _connect */
6456
6517
  /**
6457
- * Cleans up client-side resources used by the MongoCLient and . This includes:
6458
- *
6459
- * - Closes all open, unused connections (see note).
6460
- * - Ends all in-use sessions with {@link ClientSession#endSession|ClientSession.endSession()}.
6461
- * - Ends all unused sessions server-side.
6462
- * - Cleans up any resources being used for auto encryption if auto encryption is enabled.
6463
- *
6464
- * @remarks Any in-progress operations are not killed and any connections used by in progress operations
6465
- * will be cleaned up lazily as operations finish.
6466
- *
6467
- * @param force - Force close, emitting no events
6468
- */
6469
- close(force?: boolean): Promise<void>;
6518
+ * Cleans up resources managed by the MongoClient.
6519
+ *
6520
+ * The close method clears and closes all resources whose lifetimes are managed by the MongoClient.
6521
+ * Please refer to the `MongoClient` class documentation for a high level overview of the client's key features and responsibilities.
6522
+ *
6523
+ * **However,** the close method does not handle the cleanup of resources explicitly created by the user.
6524
+ * Any user-created driver resource with its own `close()` method should be explicitly closed by the user before calling MongoClient.close().
6525
+ * This method is written as a "best effort" attempt to leave behind the least amount of resources server-side when possible.
6526
+ *
6527
+ * The following list defines ideal preconditions and consequent pitfalls if they are not met.
6528
+ * The MongoClient, ClientSession, Cursors and ChangeStreams all support [explicit resource management](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html).
6529
+ * 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.
6530
+ *
6531
+ * The close method performs the following in the order listed:
6532
+ * - Client-side:
6533
+ * - **Close in-use connections**: Any connections that are currently waiting on a response from the server will be closed.
6534
+ * This is performed _first_ to avoid reaching the next step (server-side clean up) and having no available connections to check out.
6535
+ * - _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.
6536
+ * - _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.
6537
+ * - Server-side:
6538
+ * - **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.
6539
+ * - _Ideal_: Cursors are explicitly closed or completed before `client.close()` is called.
6540
+ * - _Pitfall_: `killCursors` may have to build a new connection if the in-use closure ended all pooled connections.
6541
+ * - **End active sessions**: In-use sessions created with `client.startSession()` or `client.withSession()` or implicitly by the driver will have their `.endSession()` method called.
6542
+ * 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.
6543
+ * - _Ideal_: Transaction outcomes are awaited and their corresponding explicit sessions are ended before `client.close()` is called.
6544
+ * - _Pitfall_: **This step aborts in-progress transactions**. It is advisable to observe the outcome of a transaction before closing your client.
6545
+ * - **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.
6546
+ * - _Ideal_: No user intervention is expected.
6547
+ * - _Pitfall_: None.
6548
+ *
6549
+ * 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.
6550
+ *
6551
+ * - Client-side (again):
6552
+ * - **Stop all server monitoring**: Connections kept live for detecting cluster changes and roundtrip time measurements are shutdown.
6553
+ * - **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.
6554
+ * - **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.
6555
+ * - **Close encryption-related resources**: An internal MongoClient created for communicating with `mongocryptd` or other encryption purposes is closed. (Using this same method of course!)
6556
+ *
6557
+ * 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).
6558
+ * This should allow Node.js to exit gracefully if MongoClient resources were the only active handles in the event loop.
6559
+ *
6560
+ * @param _force - currently an unused flag that has no effect. Defaults to `false`.
6561
+ */
6562
+ close(_force?: boolean): Promise<void>;
6470
6563
  private _close;
6471
6564
  /**
6472
6565
  * Create a new Db instance sharing the current socket connections.
@@ -6643,7 +6736,11 @@ declare interface MongoClientOptions extends BSONSerializeOptions, SupportedNode
6643
6736
  minPoolSize?: number;
6644
6737
  /** The maximum number of connections that may be in the process of being established concurrently by the connection pool. */
6645
6738
  maxConnecting?: number;
6646
- /** The maximum number of milliseconds that a connection can remain idle in the pool before being removed and closed. */
6739
+ /**
6740
+ * The maximum amount of time a connection should remain idle in the connection pool before being marked idle, in milliseconds.
6741
+ * If specified, this must be a number greater than or equal to 0, where 0 means there is no limit. Defaults to 0. After this
6742
+ * time passes, the idle collection can be automatically cleaned up in the background.
6743
+ */
6647
6744
  maxIdleTimeMS?: number;
6648
6745
  /** The maximum time in milliseconds that a thread can wait for a connection to become available. */
6649
6746
  waitQueueTimeoutMS?: number;
@@ -6851,14 +6948,14 @@ declare interface MongoDBLogWritable {
6851
6948
  /** @public */
6852
6949
  declare class MongoDBNamespace {
6853
6950
  db: string;
6854
- collection?: string | undefined;
6951
+ collection?: string;
6855
6952
  /**
6856
6953
  * Create a namespace object
6857
6954
  *
6858
6955
  * @param db - database name
6859
6956
  * @param collection - collection name
6860
6957
  */
6861
- constructor(db: string, collection?: string | undefined);
6958
+ constructor(db: string, collection?: string);
6862
6959
  toString(): string;
6863
6960
  withCollection(collection: string): MongoDBCollectionNamespace;
6864
6961
  static fromString(namespace?: string): MongoDBNamespace;
@@ -7005,6 +7102,15 @@ declare interface MongoDBOIDCLogEventsMap {
7005
7102
  'mongodb-oidc-plugin:inbound-http-request': (event: {
7006
7103
  url: string;
7007
7104
  }) => void;
7105
+ 'mongodb-oidc-plugin:outbound-http-request-failed': (event: {
7106
+ url: string;
7107
+ error: string;
7108
+ }) => void;
7109
+ 'mongodb-oidc-plugin:outbound-http-request-completed': (event: {
7110
+ url: string;
7111
+ status: number;
7112
+ statusText: string;
7113
+ }) => void;
7008
7114
  'mongodb-oidc-plugin:received-server-params': (event: {
7009
7115
  params: OIDCCallbackParams_2;
7010
7116
  }) => void;
@@ -7149,8 +7255,16 @@ declare interface MongoDBOIDCPluginOptions {
7149
7255
  throwOnIncompatibleSerializedState?: boolean;
7150
7256
  /**
7151
7257
  * Provide custom HTTP options for individual HTTP calls.
7258
+ *
7259
+ * @deprecated Use a custom `fetch` function instead.
7152
7260
  */
7153
7261
  customHttpOptions?: HttpOptions | ((url: string, options: Readonly<HttpOptions>) => HttpOptions);
7262
+ /**
7263
+ * Provide a custom `fetch` function to be used for HTTP calls.
7264
+ *
7265
+ * Any API that is compatible with the web `fetch` API can be used here.
7266
+ */
7267
+ customFetch?: (url: string, options: Readonly<unknown>) => Promise<Response>;
7154
7268
  /**
7155
7269
  * Pass ID tokens in place of access tokens. For debugging/working around
7156
7270
  * broken identity providers.
@@ -7256,8 +7370,10 @@ declare interface MongoOptions extends Required<Pick<MongoClientOptions, 'autoEn
7256
7370
  compressors: CompressorName[];
7257
7371
  writeConcern: WriteConcern;
7258
7372
  dbName: string;
7373
+ /** @deprecated - Will be made internal in a future major release. */
7259
7374
  metadata: ClientMetadata;
7260
- /* Excluded from this release type: extendedMetadata */
7375
+ extendedMetadata: Promise<Document_2>;
7376
+ additionalDriverInfo: DriverInfo[];
7261
7377
  /* Excluded from this release type: autoEncrypter */
7262
7378
  /* Excluded from this release type: tokenCache */
7263
7379
  proxyHost?: string;
@@ -7455,6 +7571,8 @@ declare interface OIDCCallbackParams {
7455
7571
  idpInfo?: IdPInfo;
7456
7572
  /** The refresh token, if applicable, to be used by the callback to request a new token from the issuer. */
7457
7573
  refreshToken?: string;
7574
+ /** The token audience for GCP and Azure. */
7575
+ tokenAudience?: string;
7458
7576
  }
7459
7577
 
7460
7578
  /**
@@ -7638,6 +7756,11 @@ declare interface ProxyEventMap {
7638
7756
  retryableError: boolean;
7639
7757
  retriesLeft: number;
7640
7758
  }) => void;
7759
+ 'proxy:connect': (ev: {
7760
+ agent: AgentWithInitialize;
7761
+ req: ClientRequest;
7762
+ opts: AgentConnectOpts & Partial<SecureContextOptions>;
7763
+ }) => void;
7641
7764
  }
7642
7765
 
7643
7766
  declare interface ProxyLogEmitter {
@@ -7910,7 +8033,7 @@ declare interface RenameOptions extends CommandOperationOptions {
7910
8033
 
7911
8034
  /** @public */
7912
8035
  declare interface ReplaceOneModel<TSchema extends Document_2 = Document_2> {
7913
- /** The filter to limit the replaced document. */
8036
+ /** The filter that specifies which document to replace. In the case of multiple matches, the first document matched is replaced. */
7914
8037
  filter: Filter<TSchema>;
7915
8038
  /** The document with which to replace the matched document. */
7916
8039
  replacement: WithoutId<TSchema>;
@@ -7920,6 +8043,8 @@ declare interface ReplaceOneModel<TSchema extends Document_2 = Document_2> {
7920
8043
  hint?: Hint;
7921
8044
  /** When true, creates a new document if no document matches the query. */
7922
8045
  upsert?: boolean;
8046
+ /** Specifies the sort order for the documents matched by the filter. */
8047
+ sort?: Sort;
7923
8048
  }
7924
8049
 
7925
8050
  /** @public */
@@ -7934,6 +8059,8 @@ declare interface ReplaceOptions extends CommandOperationOptions {
7934
8059
  upsert?: boolean;
7935
8060
  /** Map of parameter names and values that can be accessed using $$var (requires MongoDB 5.0). */
7936
8061
  let?: Document_2;
8062
+ /** Specifies the sort order for the documents matched by the filter. */
8063
+ sort?: Sort;
7937
8064
  }
7938
8065
 
7939
8066
  export declare class ReplicaSet<M extends GenericServerSideSchema = GenericServerSideSchema, D extends GenericDatabaseSchema = GenericDatabaseSchema> extends ShellApiWithMongoClass {
@@ -8730,7 +8857,7 @@ declare class ShellInstanceState {
8730
8857
  constructor(initialServiceProvider: ServiceProvider, messageBus?: any, cliOptions?: ShellCliOptions);
8731
8858
  fetchConnectionInfo(): Promise<ConnectionInfo_2 | undefined>;
8732
8859
  cachedConnectionInfo(): ConnectionInfo_2 | undefined;
8733
- close(force: boolean): Promise<void>;
8860
+ close(): Promise<void>;
8734
8861
  setPreFetchCollectionAndDatabaseNames(value: boolean): void;
8735
8862
  setDbFunc(newDb: any): DatabaseWithSchema;
8736
8863
  setCtx(contextObject: any): void;
@@ -8849,16 +8976,25 @@ declare interface SnippetsTransformErrorEvent {
8849
8976
 
8850
8977
  /** @public */
8851
8978
  declare type Sort = string | Exclude<SortDirection, {
8852
- $meta: string;
8853
- }> | string[] | {
8854
- [key: string]: SortDirection;
8855
- } | Map<string, SortDirection> | [string, SortDirection][] | [string, SortDirection];
8979
+ readonly $meta: string;
8980
+ }> | ReadonlyArray<string> | {
8981
+ readonly [key: string]: SortDirection;
8982
+ } | ReadonlyMap<string, SortDirection> | ReadonlyArray<readonly [string, SortDirection]> | readonly [string, SortDirection];
8856
8983
 
8857
8984
  /** @public */
8858
8985
  declare type SortDirection = 1 | -1 | 'asc' | 'desc' | 'ascending' | 'descending' | {
8986
+ readonly $meta: string;
8987
+ };
8988
+
8989
+ /** Below stricter types were created for sort that correspond with type that the cmd takes */
8990
+ /** @public */
8991
+ declare type SortDirectionForCmd = 1 | -1 | {
8859
8992
  $meta: string;
8860
8993
  };
8861
8994
 
8995
+ /** @public */
8996
+ declare type SortForCmd = Map<string, SortDirectionForCmd>;
8997
+
8862
8998
  declare type StandardJSONSchema = JSONSchema4;
8863
8999
 
8864
9000
  declare interface StartLoadingCliScriptsEvent {
@@ -8916,6 +9052,8 @@ declare type SupportedNodeConnectionOptions = SupportedTLSConnectionOptions & Su
8916
9052
  declare type SupportedSocketOptions = Pick<TcpNetConnectOpts & {
8917
9053
  autoSelectFamily?: boolean;
8918
9054
  autoSelectFamilyAttemptTimeout?: number;
9055
+ /** Node.JS socket option to set the time the first keepalive probe is sent on an idle socket. Defaults to 120000ms */
9056
+ keepAliveInitialDelay?: number;
8919
9057
  }, (typeof LEGAL_TCP_SOCKET_OPTIONS)[number]>;
8920
9058
 
8921
9059
  /** @public */
@@ -9077,23 +9215,32 @@ declare interface TopologyVersion {
9077
9215
 
9078
9216
  /**
9079
9217
  * @public
9218
+ * @deprecated - Will be made internal in a future major release.
9080
9219
  * A class maintaining state related to a server transaction. Internal Only
9081
9220
  */
9082
9221
  declare class Transaction {
9083
9222
  /* Excluded from this release type: state */
9223
+ /** @deprecated - Will be made internal in a future major release. */
9084
9224
  options: TransactionOptions;
9085
9225
  /* Excluded from this release type: _pinnedServer */
9086
9226
  /* Excluded from this release type: _recoveryToken */
9087
9227
  /* Excluded from this release type: __constructor */
9088
9228
  /* Excluded from this release type: server */
9229
+ /** @deprecated - Will be made internal in a future major release. */
9089
9230
  get recoveryToken(): Document_2 | undefined;
9231
+ /** @deprecated - Will be made internal in a future major release. */
9090
9232
  get isPinned(): boolean;
9091
- /** @returns Whether the transaction has started */
9233
+ /**
9234
+ * @deprecated - Will be made internal in a future major release.
9235
+ * @returns Whether the transaction has started
9236
+ */
9092
9237
  get isStarting(): boolean;
9093
9238
  /**
9239
+ * @deprecated - Will be made internal in a future major release.
9094
9240
  * @returns Whether this session is presently in a transaction
9095
9241
  */
9096
9242
  get isActive(): boolean;
9243
+ /** @deprecated - Will be made internal in a future major release. */
9097
9244
  get isCommitted(): boolean;
9098
9245
  /* Excluded from this release type: transition */
9099
9246
  /* Excluded from this release type: pinServer */
@@ -9274,7 +9421,7 @@ declare interface UpdateManyModel<TSchema extends Document_2 = Document_2> {
9274
9421
 
9275
9422
  /** @public */
9276
9423
  declare interface UpdateOneModel<TSchema extends Document_2 = Document_2> {
9277
- /** The filter to limit the updated documents. */
9424
+ /** The filter that specifies which document to update. In the case of multiple matches, the first document matched is updated. */
9278
9425
  filter: Filter<TSchema>;
9279
9426
  /**
9280
9427
  * The modifications to apply. The value can be either:
@@ -9290,6 +9437,8 @@ declare interface UpdateOneModel<TSchema extends Document_2 = Document_2> {
9290
9437
  hint?: Hint;
9291
9438
  /** When true, creates a new document if no document matches the query. */
9292
9439
  upsert?: boolean;
9440
+ /** Specifies the sort order for the documents matched by the filter. */
9441
+ sort?: Sort;
9293
9442
  }
9294
9443
 
9295
9444
  /** @public */
@@ -9350,6 +9499,8 @@ declare interface UpdateStatement {
9350
9499
  arrayFilters?: Document_2[];
9351
9500
  /** A document or string that specifies the index to use to support the query predicate. */
9352
9501
  hint?: Hint;
9502
+ /** Specifies the sort order for the documents matched by the filter. */
9503
+ sort?: SortForCmd;
9353
9504
  }
9354
9505
 
9355
9506
  declare interface UseEvent {
@@ -9401,7 +9552,9 @@ declare interface Writable {
9401
9552
  insertOne(database: string, collection: string, doc: Document_2, options: InsertOneOptions, dbOptions?: DbOptions): Promise<InsertOneResult>;
9402
9553
  replaceOne(database: string, collection: string, filter: Document_2, replacement: Document_2, options?: ReplaceOptions, dbOptions?: DbOptions): Promise<UpdateResult>;
9403
9554
  updateMany(database: string, collection: string, filter: Document_2, update: Document_2, options?: UpdateOptions, dbOptions?: DbOptions): Promise<UpdateResult>;
9404
- updateOne(database: string, collection: string, filter: Document_2, update: Document_2, options?: UpdateOptions, dbOptions?: DbOptions): Promise<UpdateResult>;
9555
+ updateOne(database: string, collection: string, filter: Document_2, update: Document_2, options?: UpdateOptions & {
9556
+ sort?: Document_2;
9557
+ }, dbOptions?: DbOptions): Promise<UpdateResult>;
9405
9558
  createIndexes(database: string, collection: string, indexSpecs: Document_2[], options?: CreateIndexesOptions, dbOptions?: DbOptions): Promise<string[]>;
9406
9559
  dropCollection(database: string, collection: string, options: DropCollectionOptions, dbOptions?: DbOptions): Promise<boolean>;
9407
9560
  renameCollection(database: string, oldName: string, newName: string, options?: RenameOptions, dbOptions?: DbOptions): Promise<Collection_2>;