@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.
@@ -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';
@@ -884,6 +886,10 @@ declare interface AutoEncryptionOptions {
884
886
  bypassAutoEncryption?: boolean;
885
887
  /** Allows users to bypass query analysis */
886
888
  bypassQueryAnalysis?: boolean;
889
+ /**
890
+ * Sets the expiration time for the DEK in the cache in milliseconds. Defaults to 60000. 0 means no timeout.
891
+ */
892
+ keyExpirationMS?: number;
887
893
  options?: {
888
894
  /** An optional hook to catch logging messages from the underlying encryption engine */
889
895
  logger?: (level: AutoEncryptionLoggerLevel, message: string) => void;
@@ -1214,10 +1220,10 @@ declare class BulkFindOp extends ShellApiWithMongoClass {
1214
1220
 
1215
1221
  /** @public */
1216
1222
  declare abstract class BulkOperationBase {
1217
- private collection;
1218
1223
  isOrdered: boolean;
1219
1224
  /* Excluded from this release type: s */
1220
1225
  operationId?: number;
1226
+ private collection;
1221
1227
  /* Excluded from this release type: __constructor */
1222
1228
  /**
1223
1229
  * Add a single insert document to the bulk operation
@@ -1350,7 +1356,7 @@ declare class BulkWriteResult {
1350
1356
  getRawResponse(): Document_2;
1351
1357
  /** Returns true if the bulk operation contains a write error */
1352
1358
  hasWriteErrors(): boolean;
1353
- /** Returns the number of write errors off the bulk operation */
1359
+ /** Returns the number of write errors from the bulk operation */
1354
1360
  getWriteErrorCount(): number;
1355
1361
  /** Returns a specific write error object */
1356
1362
  getWriteErrorAt(index: number): WriteError | undefined;
@@ -1386,7 +1392,10 @@ declare type CacheOptions = {
1386
1392
  aggregationSchemaTTL: number;
1387
1393
  };
1388
1394
 
1389
- /** @public */
1395
+ /**
1396
+ * @public
1397
+ * @deprecated Will be removed in favor of `AbortSignal` in the next major release.
1398
+ */
1390
1399
  declare class CancellationToken extends TypedEventEmitter<{
1391
1400
  cancel(): void;
1392
1401
  }> {
@@ -1494,7 +1503,7 @@ declare class ChangeStream<TSchema extends Document_2 = Document_2, TChange exte
1494
1503
  * @public
1495
1504
  * @see https://www.mongodb.com/docs/manual/reference/change-events/modify/#mongodb-data-modify
1496
1505
  */
1497
- declare interface ChangeStreamCollModDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID {
1506
+ declare interface ChangeStreamCollModDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID, ChangeStreamDocumentWallTime {
1498
1507
  /** Describes the type of operation represented in this change notification */
1499
1508
  operationType: 'modify';
1500
1509
  }
@@ -1503,7 +1512,7 @@ declare interface ChangeStreamCollModDocument extends ChangeStreamDocumentCommon
1503
1512
  * @public
1504
1513
  * @see https://www.mongodb.com/docs/manual/reference/change-events/create/#mongodb-data-create
1505
1514
  */
1506
- declare interface ChangeStreamCreateDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID {
1515
+ declare interface ChangeStreamCreateDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID, ChangeStreamDocumentWallTime {
1507
1516
  /** Describes the type of operation represented in this change notification */
1508
1517
  operationType: 'create';
1509
1518
  /**
@@ -1519,7 +1528,7 @@ declare interface ChangeStreamCreateDocument extends ChangeStreamDocumentCommon,
1519
1528
  * @public
1520
1529
  * @see https://www.mongodb.com/docs/manual/reference/change-events/createIndexes/#mongodb-data-createIndexes
1521
1530
  */
1522
- declare interface ChangeStreamCreateIndexDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID, ChangeStreamDocumentOperationDescription {
1531
+ declare interface ChangeStreamCreateIndexDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID, ChangeStreamDocumentOperationDescription, ChangeStreamDocumentWallTime {
1523
1532
  /** Describes the type of operation represented in this change notification */
1524
1533
  operationType: 'createIndexes';
1525
1534
  }
@@ -1575,7 +1584,7 @@ declare class ChangeStreamCursor extends ShellApiWithMongoClass {
1575
1584
  * @public
1576
1585
  * @see https://www.mongodb.com/docs/manual/reference/change-events/#delete-event
1577
1586
  */
1578
- declare interface ChangeStreamDeleteDocument<TSchema extends Document_2 = Document_2> extends ChangeStreamDocumentCommon, ChangeStreamDocumentKey<TSchema>, ChangeStreamDocumentCollectionUUID {
1587
+ declare interface ChangeStreamDeleteDocument<TSchema extends Document_2 = Document_2> extends ChangeStreamDocumentCommon, ChangeStreamDocumentKey<TSchema>, ChangeStreamDocumentCollectionUUID, ChangeStreamDocumentWallTime {
1579
1588
  /** Describes the type of operation represented in this change notification */
1580
1589
  operationType: 'delete';
1581
1590
  /** Namespace the delete event occurred on */
@@ -1668,11 +1677,21 @@ declare interface ChangeStreamDocumentOperationDescription {
1668
1677
  operationDescription?: Document_2;
1669
1678
  }
1670
1679
 
1680
+ /** @public */
1681
+ declare interface ChangeStreamDocumentWallTime {
1682
+ /**
1683
+ * The server date and time of the database operation.
1684
+ * wallTime differs from clusterTime in that clusterTime is a timestamp taken from the oplog entry associated with the database operation event.
1685
+ * @sinceServerVersion 6.0.0
1686
+ */
1687
+ wallTime?: Date;
1688
+ }
1689
+
1671
1690
  /**
1672
1691
  * @public
1673
1692
  * @see https://www.mongodb.com/docs/manual/reference/change-events/#dropdatabase-event
1674
1693
  */
1675
- declare interface ChangeStreamDropDatabaseDocument extends ChangeStreamDocumentCommon {
1694
+ declare interface ChangeStreamDropDatabaseDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentWallTime {
1676
1695
  /** Describes the type of operation represented in this change notification */
1677
1696
  operationType: 'dropDatabase';
1678
1697
  /** The database dropped */
@@ -1685,7 +1704,7 @@ declare interface ChangeStreamDropDatabaseDocument extends ChangeStreamDocumentC
1685
1704
  * @public
1686
1705
  * @see https://www.mongodb.com/docs/manual/reference/change-events/#drop-event
1687
1706
  */
1688
- declare interface ChangeStreamDropDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID {
1707
+ declare interface ChangeStreamDropDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID, ChangeStreamDocumentWallTime {
1689
1708
  /** Describes the type of operation represented in this change notification */
1690
1709
  operationType: 'drop';
1691
1710
  /** Namespace the drop event occurred on */
@@ -1697,7 +1716,7 @@ declare interface ChangeStreamDropDocument extends ChangeStreamDocumentCommon, C
1697
1716
  * @public
1698
1717
  * @see https://www.mongodb.com/docs/manual/reference/change-events/dropIndexes/#mongodb-data-dropIndexes
1699
1718
  */
1700
- declare interface ChangeStreamDropIndexDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID, ChangeStreamDocumentOperationDescription {
1719
+ declare interface ChangeStreamDropIndexDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID, ChangeStreamDocumentOperationDescription, ChangeStreamDocumentWallTime {
1701
1720
  /** Describes the type of operation represented in this change notification */
1702
1721
  operationType: 'dropIndexes';
1703
1722
  }
@@ -1724,7 +1743,7 @@ declare type ChangeStreamEvents<TSchema extends Document_2 = Document_2, TChange
1724
1743
  * @public
1725
1744
  * @see https://www.mongodb.com/docs/manual/reference/change-events/#insert-event
1726
1745
  */
1727
- declare interface ChangeStreamInsertDocument<TSchema extends Document_2 = Document_2> extends ChangeStreamDocumentCommon, ChangeStreamDocumentKey<TSchema>, ChangeStreamDocumentCollectionUUID {
1746
+ declare interface ChangeStreamInsertDocument<TSchema extends Document_2 = Document_2> extends ChangeStreamDocumentCommon, ChangeStreamDocumentKey<TSchema>, ChangeStreamDocumentCollectionUUID, ChangeStreamDocumentWallTime {
1728
1747
  /** Describes the type of operation represented in this change notification */
1729
1748
  operationType: 'insert';
1730
1749
  /** This key will contain the document being inserted */
@@ -1737,7 +1756,7 @@ declare interface ChangeStreamInsertDocument<TSchema extends Document_2 = Docume
1737
1756
  * @public
1738
1757
  * @see https://www.mongodb.com/docs/manual/reference/change-events/#invalidate-event
1739
1758
  */
1740
- declare interface ChangeStreamInvalidateDocument extends ChangeStreamDocumentCommon {
1759
+ declare interface ChangeStreamInvalidateDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentWallTime {
1741
1760
  /** Describes the type of operation represented in this change notification */
1742
1761
  operationType: 'invalidate';
1743
1762
  }
@@ -1828,7 +1847,7 @@ declare interface ChangeStreamRefineCollectionShardKeyDocument extends ChangeStr
1828
1847
  * @public
1829
1848
  * @see https://www.mongodb.com/docs/manual/reference/change-events/#rename-event
1830
1849
  */
1831
- declare interface ChangeStreamRenameDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID {
1850
+ declare interface ChangeStreamRenameDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID, ChangeStreamDocumentWallTime {
1832
1851
  /** Describes the type of operation represented in this change notification */
1833
1852
  operationType: 'rename';
1834
1853
  /** The new name for the `ns.coll` collection */
@@ -1844,7 +1863,7 @@ declare interface ChangeStreamRenameDocument extends ChangeStreamDocumentCommon,
1844
1863
  * @public
1845
1864
  * @see https://www.mongodb.com/docs/manual/reference/change-events/#replace-event
1846
1865
  */
1847
- declare interface ChangeStreamReplaceDocument<TSchema extends Document_2 = Document_2> extends ChangeStreamDocumentCommon, ChangeStreamDocumentKey<TSchema> {
1866
+ declare interface ChangeStreamReplaceDocument<TSchema extends Document_2 = Document_2> extends ChangeStreamDocumentCommon, ChangeStreamDocumentKey<TSchema>, ChangeStreamDocumentWallTime {
1848
1867
  /** Describes the type of operation represented in this change notification */
1849
1868
  operationType: 'replace';
1850
1869
  /** The fullDocument of a replace event represents the document after the insert of the replacement document */
@@ -1874,7 +1893,7 @@ declare interface ChangeStreamReshardCollectionDocument extends ChangeStreamDocu
1874
1893
  * @public
1875
1894
  * @see https://www.mongodb.com/docs/manual/reference/change-events/shardCollection/#mongodb-data-shardCollection
1876
1895
  */
1877
- declare interface ChangeStreamShardCollectionDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID, ChangeStreamDocumentOperationDescription {
1896
+ declare interface ChangeStreamShardCollectionDocument extends ChangeStreamDocumentCommon, ChangeStreamDocumentCollectionUUID, ChangeStreamDocumentOperationDescription, ChangeStreamDocumentWallTime {
1878
1897
  /** Describes the type of operation represented in this change notification */
1879
1898
  operationType: 'shardCollection';
1880
1899
  }
@@ -1891,7 +1910,7 @@ declare interface ChangeStreamSplitEvent {
1891
1910
  * @public
1892
1911
  * @see https://www.mongodb.com/docs/manual/reference/change-events/#update-event
1893
1912
  */
1894
- declare interface ChangeStreamUpdateDocument<TSchema extends Document_2 = Document_2> extends ChangeStreamDocumentCommon, ChangeStreamDocumentKey<TSchema>, ChangeStreamDocumentCollectionUUID {
1913
+ declare interface ChangeStreamUpdateDocument<TSchema extends Document_2 = Document_2> extends ChangeStreamDocumentCommon, ChangeStreamDocumentKey<TSchema>, ChangeStreamDocumentCollectionUUID, ChangeStreamDocumentWallTime {
1895
1914
  /** Describes the type of operation represented in this change notification */
1896
1915
  operationType: 'update';
1897
1916
  /**
@@ -2491,6 +2510,10 @@ declare interface ClientEncryptionOptions {
2491
2510
  * TLS options for kms providers to use.
2492
2511
  */
2493
2512
  tlsOptions?: CSFLEKMSTlsOptions;
2513
+ /**
2514
+ * Sets the expiration time for the DEK in the cache in milliseconds. Defaults to 60000. 0 means no timeout.
2515
+ */
2516
+ keyExpirationMS?: number;
2494
2517
  /**
2495
2518
  * @experimental
2496
2519
  *
@@ -2568,6 +2591,7 @@ declare type ClientInsertResult = {
2568
2591
 
2569
2592
  /**
2570
2593
  * @public
2594
+ * @deprecated This interface will be made internal in the next major release.
2571
2595
  * @see https://github.com/mongodb/specifications/blob/master/source/mongodb-handshake/handshake.md#hello-command
2572
2596
  */
2573
2597
  declare interface ClientMetadata {
@@ -2611,6 +2635,8 @@ declare interface ClientReplaceOneModel<TSchema> extends ClientWriteModel {
2611
2635
  hint?: Hint;
2612
2636
  /** When true, creates a new document if no document matches the query. */
2613
2637
  upsert?: boolean;
2638
+ /** Specifies the sort order for the documents matched by the filter. */
2639
+ sort?: Sort;
2614
2640
  }
2615
2641
 
2616
2642
  /**
@@ -2632,6 +2658,7 @@ declare class ClientSession extends TypedEventEmitter<ClientSessionEvents> imple
2632
2658
  explicit: boolean;
2633
2659
  /* Excluded from this release type: owner */
2634
2660
  defaultTransactionOptions: TransactionOptions;
2661
+ /** @deprecated - Will be made internal in the next major release */
2635
2662
  transaction: Transaction;
2636
2663
  /* Excluded from this release type: commitAttempted */
2637
2664
  readonly snapshotEnabled: boolean;
@@ -2854,6 +2881,8 @@ declare interface ClientUpdateOneModel<TSchema> extends ClientWriteModel {
2854
2881
  hint?: Hint;
2855
2882
  /** When true, creates a new document if no document matches the query. */
2856
2883
  upsert?: boolean;
2884
+ /** Specifies the sort order for the documents matched by the filter. */
2885
+ sort?: Sort;
2857
2886
  }
2858
2887
 
2859
2888
  /** @public */
@@ -2899,7 +2928,7 @@ declare interface ClientWriteModel {
2899
2928
  namespace: string;
2900
2929
  }
2901
2930
  declare interface Closable {
2902
- close(force: boolean): Promise<void>;
2931
+ close(): Promise<void>;
2903
2932
  suspend(): Promise<() => Promise<void>>;
2904
2933
  }
2905
2934
 
@@ -3064,7 +3093,9 @@ declare class Collection<M extends GenericServerSideSchema = GenericServerSideSc
3064
3093
  /*
3065
3094
  Updates a single document within the collection based on the filter.
3066
3095
  */
3067
- updateOne(filter: Document_2, update: Document_2, options?: UpdateOptions): UpdateResult_2 | Document_2;
3096
+ updateOne(filter: Document_2, update: Document_2, options?: UpdateOptions & {
3097
+ sort?: Document_2;
3098
+ }): UpdateResult_2 | Document_2;
3068
3099
  /*
3069
3100
  Compacts structured encryption data
3070
3101
  */
@@ -3382,7 +3413,9 @@ declare class Collection_2<TSchema extends Document_2 = Document_2> {
3382
3413
  * @param update - The modifications to apply
3383
3414
  * @param options - Optional settings for the command
3384
3415
  */
3385
- updateOne(filter: Filter<TSchema>, update: UpdateFilter<TSchema> | Document_2[], options?: UpdateOptions): Promise<UpdateResult<TSchema>>;
3416
+ updateOne(filter: Filter<TSchema>, update: UpdateFilter<TSchema> | Document_2[], options?: UpdateOptions & {
3417
+ sort?: Sort;
3418
+ }): Promise<UpdateResult<TSchema>>;
3386
3419
  /**
3387
3420
  * Replace a document in a collection with another document
3388
3421
  *
@@ -3920,6 +3953,7 @@ declare class CommandFailedEvent {
3920
3953
  commandName: string;
3921
3954
  failure: Error;
3922
3955
  serviceId?: ObjectId;
3956
+ databaseName: string;
3923
3957
  /* Excluded from this release type: name */
3924
3958
  /* Excluded from this release type: __constructor */
3925
3959
  get hasServiceId(): boolean;
@@ -3948,6 +3982,10 @@ declare interface CommandOperationOptions extends OperationOptions, WriteConcern
3948
3982
  retryWrites?: boolean;
3949
3983
  dbName?: string;
3950
3984
  authdb?: string;
3985
+ /**
3986
+ * @deprecated
3987
+ * This option is deprecated and will be removed in an upcoming major version.
3988
+ */
3951
3989
  noResponse?: boolean;
3952
3990
  }
3953
3991
  declare class CommandResult<T = unknown> extends ShellApiValueClass {
@@ -4003,6 +4041,7 @@ declare class CommandSucceededEvent {
4003
4041
  commandName: string;
4004
4042
  reply: unknown;
4005
4043
  serviceId?: ObjectId;
4044
+ databaseName: string;
4006
4045
  /* Excluded from this release type: name */
4007
4046
  /* Excluded from this release type: __constructor */
4008
4047
  get hasServiceId(): boolean;
@@ -5423,7 +5462,7 @@ declare class DevtoolsConnectionState {
5423
5462
  productName: string;
5424
5463
  private stateShareClient;
5425
5464
  private stateShareServer;
5426
- constructor(options: Pick<DevtoolsConnectOptions, 'productDocsLink' | 'productName' | 'oidc' | 'parentHandle'>, logger: ConnectLogEmitter, ca: string | undefined);
5465
+ constructor(options: Pick<DevtoolsConnectOptions, 'productDocsLink' | 'productName' | 'oidc' | 'parentHandle'>, logger: ConnectLogEmitter);
5427
5466
  getStateShareServer(): Promise<string>;
5428
5467
  destroy(): Promise<void>;
5429
5468
  }
@@ -5434,7 +5473,7 @@ declare interface DevtoolsConnectOptions extends MongoClientOptions {
5434
5473
  parentState?: DevtoolsConnectionState;
5435
5474
  parentHandle?: string;
5436
5475
  proxy?: DevtoolsProxyOptions | AgentWithInitialize;
5437
- applyProxyToOIDC?: boolean;
5476
+ applyProxyToOIDC?: boolean | DevtoolsProxyOptions | AgentWithInitialize;
5438
5477
  }
5439
5478
  declare interface DevtoolsProxyOptions {
5440
5479
  proxy?: string;
@@ -5445,6 +5484,7 @@ declare interface DevtoolsProxyOptions {
5445
5484
  identityKeyPassphrase?: string;
5446
5485
  };
5447
5486
  ca?: ConnectionOptions['ca'];
5487
+ caExcludeSystemCerts?: boolean;
5448
5488
  env?: Record<string, string | undefined>;
5449
5489
  }
5450
5490
 
@@ -6256,7 +6296,10 @@ declare type HostInformation = {
6256
6296
  is_do_url?: boolean;
6257
6297
  };
6258
6298
 
6259
- /** @public */
6299
+ /**
6300
+ * @public
6301
+ * @deprecated Use a custom `fetch` function instead
6302
+ */
6260
6303
  declare type HttpOptions = Partial<Pick<RequestOptions, 'agent' | 'ca' | 'cert' | 'crl' | 'headers' | 'key' | 'lookup' | 'passphrase' | 'pfx' | 'timeout'>>;
6261
6304
 
6262
6305
  /**
@@ -6773,7 +6816,7 @@ declare interface KMSProviders {
6773
6816
  }
6774
6817
 
6775
6818
  /** @public */
6776
- declare const LEGAL_TCP_SOCKET_OPTIONS: readonly ["autoSelectFamily", "autoSelectFamilyAttemptTimeout", "family", "hints", "localAddress", "localPort", "lookup"];
6819
+ declare const LEGAL_TCP_SOCKET_OPTIONS: readonly ["autoSelectFamily", "autoSelectFamilyAttemptTimeout", "keepAliveInitialDelay", "family", "hints", "localAddress", "localPort", "lookup"];
6777
6820
 
6778
6821
  /** @public */
6779
6822
  declare const LEGAL_TLS_SOCKET_OPTIONS: readonly ["allowPartialTrustChain", "ALPNProtocols", "ca", "cert", "checkServerIdentity", "ciphers", "crl", "ecdhCurve", "key", "minDHSize", "passphrase", "pfx", "rejectUnauthorized", "secureContext", "secureProtocol", "servername", "session"];
@@ -6964,7 +7007,7 @@ export declare class Mongo<M extends GenericServerSideSchema = GenericServerSide
6964
7007
  /*
6965
7008
  Closes a Mongo object, disposing of related resources and closing the underlying connection.
6966
7009
  */
6967
- close(force?: boolean): Promise<void>;
7010
+ close(): Promise<void>;
6968
7011
  _suspend(): Promise<() => Promise<void>>;
6969
7012
  /*
6970
7013
  Returns the ReadPreference Mode set for the connection.
@@ -7047,22 +7090,35 @@ export declare class Mongo<M extends GenericServerSideSchema = GenericServerSide
7047
7090
  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"];
7048
7091
 
7049
7092
  /**
7050
- * The **MongoClient** class is a class that allows for making Connections to MongoDB.
7051
7093
  * @public
7052
7094
  *
7095
+ * The **MongoClient** class is a class that allows for making Connections to MongoDB.
7096
+ *
7097
+ * **NOTE:** The programmatically provided options take precedence over the URI options.
7098
+ *
7053
7099
  * @remarks
7054
- * The programmatically provided options take precedence over the URI options.
7100
+ *
7101
+ * A MongoClient is the entry point to connecting to a MongoDB server.
7102
+ *
7103
+ * It handles a multitude of features on your application's behalf:
7104
+ * - **Server Host Connection Configuration**: A MongoClient is responsible for reading TLS cert, ca, and crl files if provided.
7105
+ * - **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.
7106
+ * - **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.
7107
+ * - **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.
7108
+ * - **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.
7109
+ * - **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.
7110
+ * - **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.
7111
+ *
7112
+ * There are many more features of a MongoClient that are not listed above.
7113
+ *
7114
+ * In order to enable these features, a number of asynchronous Node.js resources are established by the driver: Timers, FS Requests, Sockets, etc.
7115
+ * For details on cleanup, please refer to the MongoClient `close()` documentation.
7055
7116
  *
7056
7117
  * @example
7057
7118
  * ```ts
7058
7119
  * import { MongoClient } from 'mongodb';
7059
- *
7060
7120
  * // Enable command monitoring for debugging
7061
- * const client = new MongoClient('mongodb://localhost:27017', { monitorCommands: true });
7062
- *
7063
- * client.on('commandStarted', started => console.log(started));
7064
- * client.db().collection('pets');
7065
- * await client.insertOne({ name: 'spot', kind: 'dog' });
7121
+ * const client = new MongoClient('mongodb://localhost:27017?appName=mflix', { monitorCommands: true });
7066
7122
  * ```
7067
7123
  */
7068
7124
  declare class MongoClient extends TypedEventEmitter<MongoClientEvents> implements AsyncDisposable_2 {
@@ -7074,10 +7130,15 @@ declare class MongoClient extends TypedEventEmitter<MongoClientEvents> implement
7074
7130
  /**
7075
7131
  * The consolidate, parsed, transformed and merged options.
7076
7132
  */
7077
- readonly options: Readonly<Omit<MongoOptions, 'monitorCommands' | 'ca' | 'crl' | 'key' | 'cert'>> & Pick<MongoOptions, 'monitorCommands' | 'ca' | 'crl' | 'key' | 'cert'>;
7133
+ 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'>;
7078
7134
  constructor(url: string, options?: MongoClientOptions);
7079
7135
  /* Excluded from this release type: [Symbol.asyncDispose] */
7080
7136
  /* Excluded from this release type: asyncDispose */
7137
+ /**
7138
+ * Append metadata to the client metadata after instantiation.
7139
+ * @param driverInfo - Information about the application or library.
7140
+ */
7141
+ appendMetadata(driverInfo: DriverInfo): void;
7081
7142
  /* Excluded from this release type: checkForNonGenuineHosts */
7082
7143
  get serverApi(): Readonly<ServerApi | undefined>;
7083
7144
  /* Excluded from this release type: monitorCommands */
@@ -7114,19 +7175,51 @@ declare class MongoClient extends TypedEventEmitter<MongoClientEvents> implement
7114
7175
  connect(): Promise<this>;
7115
7176
  /* Excluded from this release type: _connect */
7116
7177
  /**
7117
- * Cleans up client-side resources used by the MongoCLient and . This includes:
7118
- *
7119
- * - Closes all open, unused connections (see note).
7120
- * - Ends all in-use sessions with {@link ClientSession#endSession|ClientSession.endSession()}.
7121
- * - Ends all unused sessions server-side.
7122
- * - Cleans up any resources being used for auto encryption if auto encryption is enabled.
7123
- *
7124
- * @remarks Any in-progress operations are not killed and any connections used by in progress operations
7125
- * will be cleaned up lazily as operations finish.
7126
- *
7127
- * @param force - Force close, emitting no events
7128
- */
7129
- close(force?: boolean): Promise<void>;
7178
+ * Cleans up resources managed by the MongoClient.
7179
+ *
7180
+ * The close method clears and closes all resources whose lifetimes are managed by the MongoClient.
7181
+ * Please refer to the `MongoClient` class documentation for a high level overview of the client's key features and responsibilities.
7182
+ *
7183
+ * **However,** the close method does not handle the cleanup of resources explicitly created by the user.
7184
+ * Any user-created driver resource with its own `close()` method should be explicitly closed by the user before calling MongoClient.close().
7185
+ * This method is written as a "best effort" attempt to leave behind the least amount of resources server-side when possible.
7186
+ *
7187
+ * The following list defines ideal preconditions and consequent pitfalls if they are not met.
7188
+ * The MongoClient, ClientSession, Cursors and ChangeStreams all support [explicit resource management](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html).
7189
+ * 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.
7190
+ *
7191
+ * The close method performs the following in the order listed:
7192
+ * - Client-side:
7193
+ * - **Close in-use connections**: Any connections that are currently waiting on a response from the server will be closed.
7194
+ * This is performed _first_ to avoid reaching the next step (server-side clean up) and having no available connections to check out.
7195
+ * - _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.
7196
+ * - _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.
7197
+ * - Server-side:
7198
+ * - **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.
7199
+ * - _Ideal_: Cursors are explicitly closed or completed before `client.close()` is called.
7200
+ * - _Pitfall_: `killCursors` may have to build a new connection if the in-use closure ended all pooled connections.
7201
+ * - **End active sessions**: In-use sessions created with `client.startSession()` or `client.withSession()` or implicitly by the driver will have their `.endSession()` method called.
7202
+ * 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.
7203
+ * - _Ideal_: Transaction outcomes are awaited and their corresponding explicit sessions are ended before `client.close()` is called.
7204
+ * - _Pitfall_: **This step aborts in-progress transactions**. It is advisable to observe the outcome of a transaction before closing your client.
7205
+ * - **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.
7206
+ * - _Ideal_: No user intervention is expected.
7207
+ * - _Pitfall_: None.
7208
+ *
7209
+ * 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.
7210
+ *
7211
+ * - Client-side (again):
7212
+ * - **Stop all server monitoring**: Connections kept live for detecting cluster changes and roundtrip time measurements are shutdown.
7213
+ * - **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.
7214
+ * - **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.
7215
+ * - **Close encryption-related resources**: An internal MongoClient created for communicating with `mongocryptd` or other encryption purposes is closed. (Using this same method of course!)
7216
+ *
7217
+ * 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).
7218
+ * This should allow Node.js to exit gracefully if MongoClient resources were the only active handles in the event loop.
7219
+ *
7220
+ * @param _force - currently an unused flag that has no effect. Defaults to `false`.
7221
+ */
7222
+ close(_force?: boolean): Promise<void>;
7130
7223
  private _close;
7131
7224
  /**
7132
7225
  * Create a new Db instance sharing the current socket connections.
@@ -7303,7 +7396,11 @@ declare interface MongoClientOptions extends BSONSerializeOptions, SupportedNode
7303
7396
  minPoolSize?: number;
7304
7397
  /** The maximum number of connections that may be in the process of being established concurrently by the connection pool. */
7305
7398
  maxConnecting?: number;
7306
- /** The maximum number of milliseconds that a connection can remain idle in the pool before being removed and closed. */
7399
+ /**
7400
+ * The maximum amount of time a connection should remain idle in the connection pool before being marked idle, in milliseconds.
7401
+ * 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
7402
+ * time passes, the idle collection can be automatically cleaned up in the background.
7403
+ */
7307
7404
  maxIdleTimeMS?: number;
7308
7405
  /** The maximum time in milliseconds that a thread can wait for a connection to become available. */
7309
7406
  waitQueueTimeoutMS?: number;
@@ -7510,14 +7607,14 @@ declare interface MongoDBLogWritable {
7510
7607
  /** @public */
7511
7608
  declare class MongoDBNamespace {
7512
7609
  db: string;
7513
- collection?: string | undefined;
7610
+ collection?: string;
7514
7611
  /**
7515
7612
  * Create a namespace object
7516
7613
  *
7517
7614
  * @param db - database name
7518
7615
  * @param collection - collection name
7519
7616
  */
7520
- constructor(db: string, collection?: string | undefined);
7617
+ constructor(db: string, collection?: string);
7521
7618
  toString(): string;
7522
7619
  withCollection(collection: string): MongoDBCollectionNamespace;
7523
7620
  static fromString(namespace?: string): MongoDBNamespace;
@@ -7664,6 +7761,15 @@ declare interface MongoDBOIDCLogEventsMap {
7664
7761
  'mongodb-oidc-plugin:inbound-http-request': (event: {
7665
7762
  url: string;
7666
7763
  }) => void;
7764
+ 'mongodb-oidc-plugin:outbound-http-request-failed': (event: {
7765
+ url: string;
7766
+ error: string;
7767
+ }) => void;
7768
+ 'mongodb-oidc-plugin:outbound-http-request-completed': (event: {
7769
+ url: string;
7770
+ status: number;
7771
+ statusText: string;
7772
+ }) => void;
7667
7773
  'mongodb-oidc-plugin:received-server-params': (event: {
7668
7774
  params: OIDCCallbackParams_2;
7669
7775
  }) => void;
@@ -7808,8 +7914,16 @@ declare interface MongoDBOIDCPluginOptions {
7808
7914
  throwOnIncompatibleSerializedState?: boolean;
7809
7915
  /**
7810
7916
  * Provide custom HTTP options for individual HTTP calls.
7917
+ *
7918
+ * @deprecated Use a custom `fetch` function instead.
7811
7919
  */
7812
7920
  customHttpOptions?: HttpOptions | ((url: string, options: Readonly<HttpOptions>) => HttpOptions);
7921
+ /**
7922
+ * Provide a custom `fetch` function to be used for HTTP calls.
7923
+ *
7924
+ * Any API that is compatible with the web `fetch` API can be used here.
7925
+ */
7926
+ customFetch?: (url: string, options: Readonly<unknown>) => Promise<Response>;
7813
7927
  /**
7814
7928
  * Pass ID tokens in place of access tokens. For debugging/working around
7815
7929
  * broken identity providers.
@@ -7915,8 +8029,10 @@ declare interface MongoOptions extends Required<Pick<MongoClientOptions, 'autoEn
7915
8029
  compressors: CompressorName[];
7916
8030
  writeConcern: WriteConcern;
7917
8031
  dbName: string;
8032
+ /** @deprecated - Will be made internal in a future major release. */
7918
8033
  metadata: ClientMetadata;
7919
- /* Excluded from this release type: extendedMetadata */
8034
+ extendedMetadata: Promise<Document_2>;
8035
+ additionalDriverInfo: DriverInfo[];
7920
8036
  /* Excluded from this release type: autoEncrypter */
7921
8037
  /* Excluded from this release type: tokenCache */
7922
8038
  proxyHost?: string;
@@ -8103,6 +8219,8 @@ declare interface OIDCCallbackParams {
8103
8219
  idpInfo?: IdPInfo;
8104
8220
  /** The refresh token, if applicable, to be used by the callback to request a new token from the issuer. */
8105
8221
  refreshToken?: string;
8222
+ /** The token audience for GCP and Azure. */
8223
+ tokenAudience?: string;
8106
8224
  }
8107
8225
 
8108
8226
  /**
@@ -8297,6 +8415,11 @@ declare interface ProxyEventMap {
8297
8415
  retryableError: boolean;
8298
8416
  retriesLeft: number;
8299
8417
  }) => void;
8418
+ 'proxy:connect': (ev: {
8419
+ agent: AgentWithInitialize;
8420
+ req: ClientRequest;
8421
+ opts: AgentConnectOpts & Partial<SecureContextOptions>;
8422
+ }) => void;
8300
8423
  }
8301
8424
  declare interface ProxyLogEmitter {
8302
8425
  on<K extends keyof ProxyEventMap>(event: K, listener: ProxyEventMap[K]): this;
@@ -8560,7 +8683,7 @@ declare interface RenameOptions extends CommandOperationOptions {
8560
8683
 
8561
8684
  /** @public */
8562
8685
  declare interface ReplaceOneModel<TSchema extends Document_2 = Document_2> {
8563
- /** The filter to limit the replaced document. */
8686
+ /** The filter that specifies which document to replace. In the case of multiple matches, the first document matched is replaced. */
8564
8687
  filter: Filter<TSchema>;
8565
8688
  /** The document with which to replace the matched document. */
8566
8689
  replacement: WithoutId<TSchema>;
@@ -8570,6 +8693,8 @@ declare interface ReplaceOneModel<TSchema extends Document_2 = Document_2> {
8570
8693
  hint?: Hint;
8571
8694
  /** When true, creates a new document if no document matches the query. */
8572
8695
  upsert?: boolean;
8696
+ /** Specifies the sort order for the documents matched by the filter. */
8697
+ sort?: Sort;
8573
8698
  }
8574
8699
 
8575
8700
  /** @public */
@@ -8584,6 +8709,8 @@ declare interface ReplaceOptions extends CommandOperationOptions {
8584
8709
  upsert?: boolean;
8585
8710
  /** Map of parameter names and values that can be accessed using $$var (requires MongoDB 5.0). */
8586
8711
  let?: Document_2;
8712
+ /** Specifies the sort order for the documents matched by the filter. */
8713
+ sort?: Sort;
8587
8714
  }
8588
8715
  export declare class ReplicaSet<M extends GenericServerSideSchema = GenericServerSideSchema, D extends GenericDatabaseSchema = GenericDatabaseSchema> extends ShellApiWithMongoClass {
8589
8716
  _database: DatabaseWithSchema<M, D>;
@@ -9642,7 +9769,7 @@ declare class ShellInstanceState {
9642
9769
  constructor(initialServiceProvider: ServiceProvider, messageBus?: any, cliOptions?: ShellCliOptions);
9643
9770
  fetchConnectionInfo(): Promise<ConnectionInfo_2 | undefined>;
9644
9771
  cachedConnectionInfo(): ConnectionInfo_2 | undefined;
9645
- close(force: boolean): Promise<void>;
9772
+ close(): Promise<void>;
9646
9773
  setPreFetchCollectionAndDatabaseNames(value: boolean): void;
9647
9774
  setDbFunc(newDb: any): DatabaseWithSchema;
9648
9775
  setCtx(contextObject: any): void;
@@ -9762,15 +9889,24 @@ declare interface SnippetsTransformErrorEvent {
9762
9889
 
9763
9890
  /** @public */
9764
9891
  declare type Sort = string | Exclude<SortDirection, {
9765
- $meta: string;
9766
- }> | string[] | {
9767
- [key: string]: SortDirection;
9768
- } | Map<string, SortDirection> | [string, SortDirection][] | [string, SortDirection];
9892
+ readonly $meta: string;
9893
+ }> | ReadonlyArray<string> | {
9894
+ readonly [key: string]: SortDirection;
9895
+ } | ReadonlyMap<string, SortDirection> | ReadonlyArray<readonly [string, SortDirection]> | readonly [string, SortDirection];
9769
9896
 
9770
9897
  /** @public */
9771
9898
  declare type SortDirection = 1 | -1 | 'asc' | 'desc' | 'ascending' | 'descending' | {
9899
+ readonly $meta: string;
9900
+ };
9901
+
9902
+ /** Below stricter types were created for sort that correspond with type that the cmd takes */
9903
+ /** @public */
9904
+ declare type SortDirectionForCmd = 1 | -1 | {
9772
9905
  $meta: string;
9773
9906
  };
9907
+
9908
+ /** @public */
9909
+ declare type SortForCmd = Map<string, SortDirectionForCmd>;
9774
9910
  declare type StandardJSONSchema = JSONSchema4;
9775
9911
  declare interface StartLoadingCliScriptsEvent {
9776
9912
  usesShellOption: boolean;
@@ -9859,6 +9995,8 @@ declare type SupportedNodeConnectionOptions = SupportedTLSConnectionOptions & Su
9859
9995
  declare type SupportedSocketOptions = Pick<TcpNetConnectOpts & {
9860
9996
  autoSelectFamily?: boolean;
9861
9997
  autoSelectFamilyAttemptTimeout?: number;
9998
+ /** Node.JS socket option to set the time the first keepalive probe is sent on an idle socket. Defaults to 120000ms */
9999
+ keepAliveInitialDelay?: number;
9862
10000
  }, (typeof LEGAL_TCP_SOCKET_OPTIONS)[number]>;
9863
10001
 
9864
10002
  /** @public */
@@ -10019,23 +10157,32 @@ declare interface TopologyVersion {
10019
10157
 
10020
10158
  /**
10021
10159
  * @public
10160
+ * @deprecated - Will be made internal in a future major release.
10022
10161
  * A class maintaining state related to a server transaction. Internal Only
10023
10162
  */
10024
10163
  declare class Transaction {
10025
10164
  /* Excluded from this release type: state */
10165
+ /** @deprecated - Will be made internal in a future major release. */
10026
10166
  options: TransactionOptions;
10027
10167
  /* Excluded from this release type: _pinnedServer */
10028
10168
  /* Excluded from this release type: _recoveryToken */
10029
10169
  /* Excluded from this release type: __constructor */
10030
10170
  /* Excluded from this release type: server */
10171
+ /** @deprecated - Will be made internal in a future major release. */
10031
10172
  get recoveryToken(): Document_2 | undefined;
10173
+ /** @deprecated - Will be made internal in a future major release. */
10032
10174
  get isPinned(): boolean;
10033
- /** @returns Whether the transaction has started */
10175
+ /**
10176
+ * @deprecated - Will be made internal in a future major release.
10177
+ * @returns Whether the transaction has started
10178
+ */
10034
10179
  get isStarting(): boolean;
10035
10180
  /**
10181
+ * @deprecated - Will be made internal in a future major release.
10036
10182
  * @returns Whether this session is presently in a transaction
10037
10183
  */
10038
10184
  get isActive(): boolean;
10185
+ /** @deprecated - Will be made internal in a future major release. */
10039
10186
  get isCommitted(): boolean;
10040
10187
  /* Excluded from this release type: transition */
10041
10188
  /* Excluded from this release type: pinServer */
@@ -10216,7 +10363,7 @@ declare interface UpdateManyModel<TSchema extends Document_2 = Document_2> {
10216
10363
 
10217
10364
  /** @public */
10218
10365
  declare interface UpdateOneModel<TSchema extends Document_2 = Document_2> {
10219
- /** The filter to limit the updated documents. */
10366
+ /** The filter that specifies which document to update. In the case of multiple matches, the first document matched is updated. */
10220
10367
  filter: Filter<TSchema>;
10221
10368
  /**
10222
10369
  * The modifications to apply. The value can be either:
@@ -10232,6 +10379,8 @@ declare interface UpdateOneModel<TSchema extends Document_2 = Document_2> {
10232
10379
  hint?: Hint;
10233
10380
  /** When true, creates a new document if no document matches the query. */
10234
10381
  upsert?: boolean;
10382
+ /** Specifies the sort order for the documents matched by the filter. */
10383
+ sort?: Sort;
10235
10384
  }
10236
10385
 
10237
10386
  /** @public */
@@ -10291,6 +10440,8 @@ declare interface UpdateStatement {
10291
10440
  arrayFilters?: Document_2[];
10292
10441
  /** A document or string that specifies the index to use to support the query predicate. */
10293
10442
  hint?: Hint;
10443
+ /** Specifies the sort order for the documents matched by the filter. */
10444
+ sort?: SortForCmd;
10294
10445
  }
10295
10446
  declare interface UseEvent {
10296
10447
  db: string;
@@ -10337,7 +10488,9 @@ declare interface Writable {
10337
10488
  insertOne(database: string, collection: string, doc: Document_2, options: InsertOneOptions, dbOptions?: DbOptions): Promise<InsertOneResult>;
10338
10489
  replaceOne(database: string, collection: string, filter: Document_2, replacement: Document_2, options?: ReplaceOptions, dbOptions?: DbOptions): Promise<UpdateResult>;
10339
10490
  updateMany(database: string, collection: string, filter: Document_2, update: Document_2, options?: UpdateOptions, dbOptions?: DbOptions): Promise<UpdateResult>;
10340
- updateOne(database: string, collection: string, filter: Document_2, update: Document_2, options?: UpdateOptions, dbOptions?: DbOptions): Promise<UpdateResult>;
10491
+ updateOne(database: string, collection: string, filter: Document_2, update: Document_2, options?: UpdateOptions & {
10492
+ sort?: Document_2;
10493
+ }, dbOptions?: DbOptions): Promise<UpdateResult>;
10341
10494
  createIndexes(database: string, collection: string, indexSpecs: Document_2[], options?: CreateIndexesOptions, dbOptions?: DbOptions): Promise<string[]>;
10342
10495
  dropCollection(database: string, collection: string, options: DropCollectionOptions, dbOptions?: DbOptions): Promise<boolean>;
10343
10496
  renameCollection(database: string, oldName: string, newName: string, options?: RenameOptions, dbOptions?: DbOptions): Promise<Collection_2>;