mongodb 5.2.0 → 5.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/lib/admin.js +18 -0
  2. package/lib/admin.js.map +1 -1
  3. package/lib/bulk/common.js +28 -7
  4. package/lib/bulk/common.js.map +1 -1
  5. package/lib/cmap/auth/mongo_credentials.js +29 -2
  6. package/lib/cmap/auth/mongo_credentials.js.map +1 -1
  7. package/lib/cmap/auth/mongodb_oidc/aws_service_workflow.js +5 -3
  8. package/lib/cmap/auth/mongodb_oidc/aws_service_workflow.js.map +1 -1
  9. package/lib/cmap/auth/mongodb_oidc/cache.js +28 -0
  10. package/lib/cmap/auth/mongodb_oidc/cache.js.map +1 -0
  11. package/lib/cmap/auth/mongodb_oidc/callback_lock_cache.js +83 -0
  12. package/lib/cmap/auth/mongodb_oidc/callback_lock_cache.js.map +1 -0
  13. package/lib/cmap/auth/mongodb_oidc/callback_workflow.js +138 -112
  14. package/lib/cmap/auth/mongodb_oidc/callback_workflow.js.map +1 -1
  15. package/lib/cmap/auth/mongodb_oidc/service_workflow.js +4 -2
  16. package/lib/cmap/auth/mongodb_oidc/service_workflow.js.map +1 -1
  17. package/lib/cmap/auth/mongodb_oidc/token_entry_cache.js +12 -56
  18. package/lib/cmap/auth/mongodb_oidc/token_entry_cache.js.map +1 -1
  19. package/lib/cmap/auth/mongodb_oidc.js +17 -13
  20. package/lib/cmap/auth/mongodb_oidc.js.map +1 -1
  21. package/lib/cmap/command_monitoring_events.js +6 -0
  22. package/lib/cmap/command_monitoring_events.js.map +1 -1
  23. package/lib/cmap/connect.js +1 -0
  24. package/lib/cmap/connect.js.map +1 -1
  25. package/lib/cmap/connection.js +12 -12
  26. package/lib/cmap/connection.js.map +1 -1
  27. package/lib/cmap/connection_pool.js +7 -3
  28. package/lib/cmap/connection_pool.js.map +1 -1
  29. package/lib/cmap/connection_pool_events.js +28 -3
  30. package/lib/cmap/connection_pool_events.js.map +1 -1
  31. package/lib/cmap/handshake/client_metadata.js +173 -0
  32. package/lib/cmap/handshake/client_metadata.js.map +1 -0
  33. package/lib/cmap/wire_protocol/constants.js +2 -2
  34. package/lib/cmap/wire_protocol/shared.js +2 -2
  35. package/lib/cmap/wire_protocol/shared.js.map +1 -1
  36. package/lib/collection.js +3 -0
  37. package/lib/collection.js.map +1 -1
  38. package/lib/connection_string.js +48 -53
  39. package/lib/connection_string.js.map +1 -1
  40. package/lib/constants.js +11 -0
  41. package/lib/constants.js.map +1 -1
  42. package/lib/cursor/abstract_cursor.js +1 -0
  43. package/lib/cursor/abstract_cursor.js.map +1 -1
  44. package/lib/db.js +18 -0
  45. package/lib/db.js.map +1 -1
  46. package/lib/mongo_client.js +16 -0
  47. package/lib/mongo_client.js.map +1 -1
  48. package/lib/mongo_logger.js +258 -27
  49. package/lib/mongo_logger.js.map +1 -1
  50. package/lib/operations/add_user.js.map +1 -1
  51. package/lib/operations/find.js +0 -7
  52. package/lib/operations/find.js.map +1 -1
  53. package/lib/operations/run_command.js.map +1 -1
  54. package/lib/operations/stats.js.map +1 -1
  55. package/lib/operations/update.js.map +1 -1
  56. package/lib/sdam/srv_polling.js +1 -15
  57. package/lib/sdam/srv_polling.js.map +1 -1
  58. package/lib/sdam/topology.js.map +1 -1
  59. package/lib/utils.js +48 -35
  60. package/lib/utils.js.map +1 -1
  61. package/mongodb.d.ts +247 -47
  62. package/package.json +3 -3
  63. package/src/admin.ts +18 -0
  64. package/src/bulk/common.ts +28 -7
  65. package/src/change_stream.ts +1 -1
  66. package/src/cmap/auth/mongo_credentials.ts +35 -2
  67. package/src/cmap/auth/mongodb_oidc/aws_service_workflow.ts +6 -3
  68. package/src/cmap/auth/mongodb_oidc/cache.ts +27 -0
  69. package/src/cmap/auth/mongodb_oidc/callback_lock_cache.ts +107 -0
  70. package/src/cmap/auth/mongodb_oidc/callback_workflow.ts +208 -171
  71. package/src/cmap/auth/mongodb_oidc/service_workflow.ts +5 -3
  72. package/src/cmap/auth/mongodb_oidc/token_entry_cache.ts +17 -96
  73. package/src/cmap/auth/mongodb_oidc.ts +61 -37
  74. package/src/cmap/command_monitoring_events.ts +13 -1
  75. package/src/cmap/connect.ts +3 -1
  76. package/src/cmap/connection.ts +16 -13
  77. package/src/cmap/connection_pool.ts +14 -4
  78. package/src/cmap/connection_pool_events.ts +68 -6
  79. package/src/cmap/handshake/client_metadata.ts +272 -0
  80. package/src/cmap/wire_protocol/constants.ts +2 -2
  81. package/src/cmap/wire_protocol/shared.ts +2 -3
  82. package/src/collection.ts +6 -3
  83. package/src/connection_string.ts +55 -55
  84. package/src/constants.ts +11 -0
  85. package/src/cursor/abstract_cursor.ts +1 -0
  86. package/src/db.ts +18 -0
  87. package/src/index.ts +24 -6
  88. package/src/mongo_client.ts +50 -6
  89. package/src/mongo_logger.ts +363 -44
  90. package/src/operations/add_user.ts +8 -2
  91. package/src/operations/find.ts +0 -10
  92. package/src/operations/run_command.ts +40 -3
  93. package/src/operations/stats.ts +11 -2
  94. package/src/operations/update.ts +8 -4
  95. package/src/sdam/srv_polling.ts +1 -16
  96. package/src/sdam/topology.ts +1 -3
  97. package/src/utils.ts +54 -73
  98. package/lib/cmap/auth/mongodb_oidc/workflow.js +0 -3
  99. package/lib/cmap/auth/mongodb_oidc/workflow.js.map +0 -1
  100. package/src/cmap/auth/mongodb_oidc/workflow.ts +0 -21
package/mongodb.d.ts CHANGED
@@ -81,6 +81,7 @@ export declare abstract class AbstractCursor<TSchema = any, CursorEvents extends
81
81
  * If the iterator returns `false`, iteration will stop.
82
82
  *
83
83
  * @param iterator - The iteration callback.
84
+ * @deprecated - Will be removed in a future release. Use for await...of instead.
84
85
  */
85
86
  forEach(iterator: (doc: TSchema) => boolean | void): Promise<void>;
86
87
  close(): Promise<void>;
@@ -242,7 +243,10 @@ export declare type AddToSetOperators<Type> = {
242
243
  $each?: Array<Flatten<Type>>;
243
244
  };
244
245
 
245
- /** @public */
246
+ /**
247
+ * @public
248
+ * @deprecated Use the createUser command directly instead.
249
+ */
246
250
  export declare interface AddUserOptions extends CommandOperationOptions {
247
251
  /** Roles associated with the created user */
248
252
  roles?: string | string[] | RoleSpecification | RoleSpecification[];
@@ -275,6 +279,22 @@ export declare class Admin {
275
279
  /**
276
280
  * Execute a command
277
281
  *
282
+ * The driver will ensure the following fields are attached to the command sent to the server:
283
+ * - `lsid` - sourced from an implicit session or options.session
284
+ * - `$readPreference` - defaults to primary or can be configured by options.readPreference
285
+ * - `$db` - sourced from the name of this database
286
+ *
287
+ * If the client has a serverApi setting:
288
+ * - `apiVersion`
289
+ * - `apiStrict`
290
+ * - `apiDeprecationErrors`
291
+ *
292
+ * When in a transaction:
293
+ * - `readConcern` - sourced from readConcern set on the TransactionOptions
294
+ * - `writeConcern` - sourced from writeConcern set on the TransactionOptions
295
+ *
296
+ * Attaching any of the above fields to the command will have no effect as the driver will overwrite the value.
297
+ *
278
298
  * @param command - The command to execute
279
299
  * @param options - Optional settings for the command
280
300
  */
@@ -309,6 +329,8 @@ export declare class Admin {
309
329
  * @param username - The username for the new user
310
330
  * @param passwordOrOptions - An optional password for the new user, or the options for the command
311
331
  * @param options - Optional settings for the command
332
+ * @deprecated Use the createUser command in `db.command()` instead.
333
+ * @see https://www.mongodb.com/docs/manual/reference/command/createUser/
312
334
  */
313
335
  addUser(username: string, passwordOrOptions?: string | AddUserOptions, options?: AddUserOptions): Promise<Document>;
314
336
  /**
@@ -531,6 +553,8 @@ export declare interface AuthMechanismProperties extends Document {
531
553
  REFRESH_TOKEN_CALLBACK?: OIDCRefreshFunction;
532
554
  /** @experimental */
533
555
  PROVIDER_NAME?: 'aws';
556
+ /** @experimental */
557
+ ALLOWED_HOSTS?: string[];
534
558
  }
535
559
 
536
560
  /** @public */
@@ -935,19 +959,40 @@ export declare class BulkWriteResult {
935
959
  /* Excluded from this release type: __constructor */
936
960
  /** Evaluates to true if the bulk operation correctly executes */
937
961
  get ok(): number;
938
- /** The number of inserted documents */
962
+ /**
963
+ * The number of inserted documents
964
+ * @deprecated Use insertedCount instead.
965
+ */
939
966
  get nInserted(): number;
940
- /** Number of upserted documents */
967
+ /**
968
+ * Number of upserted documents
969
+ * @deprecated User upsertedCount instead.
970
+ */
941
971
  get nUpserted(): number;
942
- /** Number of matched documents */
972
+ /**
973
+ * Number of matched documents
974
+ * @deprecated Use matchedCount instead.
975
+ */
943
976
  get nMatched(): number;
944
- /** Number of documents updated physically on disk */
977
+ /**
978
+ * Number of documents updated physically on disk
979
+ * @deprecated Use modifiedCount instead.
980
+ */
945
981
  get nModified(): number;
946
- /** Number of removed documents */
982
+ /**
983
+ * Number of removed documents
984
+ * @deprecated Use deletedCount instead.
985
+ */
947
986
  get nRemoved(): number;
948
- /** Returns an array of all inserted ids */
987
+ /**
988
+ * Returns an array of all inserted ids
989
+ * @deprecated Use insertedIds instead.
990
+ */
949
991
  getInsertedIds(): Document[];
950
- /** Returns an array of all upserted ids */
992
+ /**
993
+ * Returns an array of all upserted ids
994
+ * @deprecated Use upsertedIds instead.
995
+ */
951
996
  getUpsertedIds(): Document[];
952
997
  /** Returns the upserted id at the given index */
953
998
  getUpsertedIdAt(index: number): Document | undefined;
@@ -1038,7 +1083,7 @@ export declare class ChangeStream<TSchema extends Document = Document, TChange e
1038
1083
  /**
1039
1084
  * Try to get the next available document from the Change Stream's cursor or `null` if an empty batch is returned
1040
1085
  */
1041
- tryNext(): Promise<Document | null>;
1086
+ tryNext(): Promise<TChange | null>;
1042
1087
  [Symbol.asyncIterator](): AsyncGenerator<TChange, void, void>;
1043
1088
  /** Is the cursor closed */
1044
1089
  get closed(): boolean;
@@ -1433,14 +1478,22 @@ export declare interface ClientMetadata {
1433
1478
  };
1434
1479
  os: {
1435
1480
  type: string;
1436
- name: NodeJS.Platform;
1437
- architecture: string;
1438
- version: string;
1481
+ name?: NodeJS.Platform;
1482
+ architecture?: string;
1483
+ version?: string;
1439
1484
  };
1440
1485
  platform: string;
1441
1486
  application?: {
1442
1487
  name: string;
1443
1488
  };
1489
+ /** FaaS environment information */
1490
+ env?: {
1491
+ name: 'aws.lambda' | 'gcp.func' | 'azure.func' | 'vercel';
1492
+ timeout_sec?: Int32;
1493
+ memory_mb?: Int32;
1494
+ region?: string;
1495
+ url?: string;
1496
+ };
1444
1497
  }
1445
1498
 
1446
1499
  /** @public */
@@ -1728,7 +1781,7 @@ export declare class Collection<TSchema extends Document = Document> {
1728
1781
  * @param update - The update operations to be applied to the document
1729
1782
  * @param options - Optional settings for the command
1730
1783
  */
1731
- updateOne(filter: Filter<TSchema>, update: UpdateFilter<TSchema> | Partial<TSchema>, options?: UpdateOptions): Promise<UpdateResult>;
1784
+ updateOne(filter: Filter<TSchema>, update: UpdateFilter<TSchema> | Partial<TSchema>, options?: UpdateOptions): Promise<UpdateResult<TSchema>>;
1732
1785
  /**
1733
1786
  * Replace a document in a collection with another document
1734
1787
  *
@@ -1736,7 +1789,7 @@ export declare class Collection<TSchema extends Document = Document> {
1736
1789
  * @param replacement - The Document that replaces the matching document
1737
1790
  * @param options - Optional settings for the command
1738
1791
  */
1739
- replaceOne(filter: Filter<TSchema>, replacement: WithoutId<TSchema>, options?: ReplaceOptions): Promise<UpdateResult | Document>;
1792
+ replaceOne(filter: Filter<TSchema>, replacement: WithoutId<TSchema>, options?: ReplaceOptions): Promise<UpdateResult<TSchema> | Document>;
1740
1793
  /**
1741
1794
  * Update multiple documents in a collection
1742
1795
  *
@@ -1744,7 +1797,7 @@ export declare class Collection<TSchema extends Document = Document> {
1744
1797
  * @param update - The update operations to be applied to the documents
1745
1798
  * @param options - Optional settings for the command
1746
1799
  */
1747
- updateMany(filter: Filter<TSchema>, update: UpdateFilter<TSchema>, options?: UpdateOptions): Promise<UpdateResult>;
1800
+ updateMany(filter: Filter<TSchema>, update: UpdateFilter<TSchema>, options?: UpdateOptions): Promise<UpdateResult<TSchema>>;
1748
1801
  /**
1749
1802
  * Delete a document from a collection
1750
1803
  *
@@ -1962,6 +2015,9 @@ export declare class Collection<TSchema extends Document = Document> {
1962
2015
  /**
1963
2016
  * Get all the collection statistics.
1964
2017
  *
2018
+ * @deprecated the `collStats` operation will be removed in the next major release. Please
2019
+ * use an aggregation pipeline with the [`$collStats`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/) stage instead
2020
+ *
1965
2021
  * @param options - Optional settings for the command
1966
2022
  */
1967
2023
  stats(options?: CollStatsOptions): Promise<CollStats>;
@@ -2090,6 +2146,8 @@ export declare interface CollectionOptions extends BSONSerializeOptions, WriteCo
2090
2146
  /* Excluded from this release type: CollectionPrivate */
2091
2147
 
2092
2148
  /**
2149
+ * @deprecated the `collStats` operation will be removed in the next major release. Please
2150
+ * use an aggregation pipeline with the [`$collStats`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/) stage instead
2093
2151
  * @public
2094
2152
  * @see https://www.mongodb.com/docs/manual/reference/command/collStats/
2095
2153
  */
@@ -2142,7 +2200,11 @@ export declare interface CollStats extends Document {
2142
2200
  scaleFactor: number;
2143
2201
  }
2144
2202
 
2145
- /** @public */
2203
+ /**
2204
+ * @public
2205
+ * @deprecated the `collStats` operation will be removed in the next major release. Please
2206
+ * use an aggregation pipeline with the [`$collStats`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/) stage instead
2207
+ */
2146
2208
  export declare interface CollStatsOptions extends CommandOperationOptions {
2147
2209
  /** Divide the returned sizes by scale value. */
2148
2210
  scale?: number;
@@ -2161,6 +2223,7 @@ export declare class CommandFailedEvent {
2161
2223
  commandName: string;
2162
2224
  failure: Error;
2163
2225
  serviceId?: ObjectId;
2226
+ /* Excluded from this release type: name */
2164
2227
  /* Excluded from this release type: __constructor */
2165
2228
  get hasServiceId(): boolean;
2166
2229
  }
@@ -2206,6 +2269,7 @@ export declare class CommandStartedEvent {
2206
2269
  address: string;
2207
2270
  connectionId?: string | number;
2208
2271
  serviceId?: ObjectId;
2272
+ /* Excluded from this release type: name */
2209
2273
  /* Excluded from this release type: __constructor */
2210
2274
  get hasServiceId(): boolean;
2211
2275
  }
@@ -2223,6 +2287,7 @@ export declare class CommandSucceededEvent {
2223
2287
  commandName: string;
2224
2288
  reply: unknown;
2225
2289
  serviceId?: ObjectId;
2290
+ /* Excluded from this release type: name */
2226
2291
  /* Excluded from this release type: __constructor */
2227
2292
  get hasServiceId(): boolean;
2228
2293
  }
@@ -2249,6 +2314,28 @@ export declare type Condition<T> = AlternativeType<T> | FilterOperators<Alternat
2249
2314
 
2250
2315
  /* Excluded from this release type: Connection */
2251
2316
 
2317
+ /* Excluded from this release type: CONNECTION_CHECK_OUT_FAILED */
2318
+
2319
+ /* Excluded from this release type: CONNECTION_CHECK_OUT_STARTED */
2320
+
2321
+ /* Excluded from this release type: CONNECTION_CHECKED_IN */
2322
+
2323
+ /* Excluded from this release type: CONNECTION_CHECKED_OUT */
2324
+
2325
+ /* Excluded from this release type: CONNECTION_CLOSED */
2326
+
2327
+ /* Excluded from this release type: CONNECTION_CREATED */
2328
+
2329
+ /* Excluded from this release type: CONNECTION_POOL_CLEARED */
2330
+
2331
+ /* Excluded from this release type: CONNECTION_POOL_CLOSED */
2332
+
2333
+ /* Excluded from this release type: CONNECTION_POOL_CREATED */
2334
+
2335
+ /* Excluded from this release type: CONNECTION_POOL_READY */
2336
+
2337
+ /* Excluded from this release type: CONNECTION_READY */
2338
+
2252
2339
  /**
2253
2340
  * An event published when a connection is checked into the connection pool
2254
2341
  * @public
@@ -2257,6 +2344,7 @@ export declare type Condition<T> = AlternativeType<T> | FilterOperators<Alternat
2257
2344
  export declare class ConnectionCheckedInEvent extends ConnectionPoolMonitoringEvent {
2258
2345
  /** The id of the connection */
2259
2346
  connectionId: number | '<monitor>';
2347
+ /* Excluded from this release type: name */
2260
2348
  /* Excluded from this release type: __constructor */
2261
2349
  }
2262
2350
 
@@ -2268,6 +2356,7 @@ export declare class ConnectionCheckedInEvent extends ConnectionPoolMonitoringEv
2268
2356
  export declare class ConnectionCheckedOutEvent extends ConnectionPoolMonitoringEvent {
2269
2357
  /** The id of the connection */
2270
2358
  connectionId: number | '<monitor>';
2359
+ /* Excluded from this release type: name */
2271
2360
  /* Excluded from this release type: __constructor */
2272
2361
  }
2273
2362
 
@@ -2278,7 +2367,9 @@ export declare class ConnectionCheckedOutEvent extends ConnectionPoolMonitoringE
2278
2367
  */
2279
2368
  export declare class ConnectionCheckOutFailedEvent extends ConnectionPoolMonitoringEvent {
2280
2369
  /** The reason the attempt to check out failed */
2281
- reason: AnyError | string;
2370
+ reason: string;
2371
+ /* Excluded from this release type: error */
2372
+ /* Excluded from this release type: name */
2282
2373
  /* Excluded from this release type: __constructor */
2283
2374
  }
2284
2375
 
@@ -2288,6 +2379,7 @@ export declare class ConnectionCheckOutFailedEvent extends ConnectionPoolMonitor
2288
2379
  * @category Event
2289
2380
  */
2290
2381
  export declare class ConnectionCheckOutStartedEvent extends ConnectionPoolMonitoringEvent {
2382
+ /* Excluded from this release type: name */
2291
2383
  /* Excluded from this release type: __constructor */
2292
2384
  }
2293
2385
 
@@ -2302,6 +2394,8 @@ export declare class ConnectionClosedEvent extends ConnectionPoolMonitoringEvent
2302
2394
  /** The reason the connection was closed */
2303
2395
  reason: string;
2304
2396
  serviceId?: ObjectId;
2397
+ /* Excluded from this release type: name */
2398
+ /* Excluded from this release type: error */
2305
2399
  /* Excluded from this release type: __constructor */
2306
2400
  }
2307
2401
 
@@ -2313,6 +2407,7 @@ export declare class ConnectionClosedEvent extends ConnectionPoolMonitoringEvent
2313
2407
  export declare class ConnectionCreatedEvent extends ConnectionPoolMonitoringEvent {
2314
2408
  /** A monotonically increasing, per-pool id for the newly created connection */
2315
2409
  connectionId: number | '<monitor>';
2410
+ /* Excluded from this release type: name */
2316
2411
  /* Excluded from this release type: __constructor */
2317
2412
  }
2318
2413
 
@@ -2340,7 +2435,9 @@ export declare interface ConnectionOptions extends SupportedNodeConnectionOption
2340
2435
  credentials?: MongoCredentials;
2341
2436
  connectTimeoutMS?: number;
2342
2437
  tls: boolean;
2438
+ /** @deprecated - Will not be able to turn off in the future. */
2343
2439
  keepAlive?: boolean;
2440
+ /** @deprecated - Will not be configurable in the future. */
2344
2441
  keepAliveInitialDelay?: number;
2345
2442
  noDelay?: boolean;
2346
2443
  socketTimeoutMS?: number;
@@ -2358,6 +2455,7 @@ export declare interface ConnectionOptions extends SupportedNodeConnectionOption
2358
2455
  export declare class ConnectionPoolClearedEvent extends ConnectionPoolMonitoringEvent {
2359
2456
  /* Excluded from this release type: serviceId */
2360
2457
  interruptInUseConnections?: boolean;
2458
+ /* Excluded from this release type: name */
2361
2459
  /* Excluded from this release type: __constructor */
2362
2460
  }
2363
2461
 
@@ -2367,6 +2465,7 @@ export declare class ConnectionPoolClearedEvent extends ConnectionPoolMonitoring
2367
2465
  * @category Event
2368
2466
  */
2369
2467
  export declare class ConnectionPoolClosedEvent extends ConnectionPoolMonitoringEvent {
2468
+ /* Excluded from this release type: name */
2370
2469
  /* Excluded from this release type: __constructor */
2371
2470
  }
2372
2471
 
@@ -2378,6 +2477,7 @@ export declare class ConnectionPoolClosedEvent extends ConnectionPoolMonitoringE
2378
2477
  export declare class ConnectionPoolCreatedEvent extends ConnectionPoolMonitoringEvent {
2379
2478
  /** The options used to create this connection pool */
2380
2479
  options?: ConnectionPoolOptions;
2480
+ /* Excluded from this release type: name */
2381
2481
  /* Excluded from this release type: __constructor */
2382
2482
  }
2383
2483
 
@@ -2403,11 +2503,12 @@ export declare type ConnectionPoolEvents = {
2403
2503
  * @public
2404
2504
  * @category Event
2405
2505
  */
2406
- export declare class ConnectionPoolMonitoringEvent {
2506
+ export declare abstract class ConnectionPoolMonitoringEvent {
2407
2507
  /** A timestamp when the event was created */
2408
2508
  time: Date;
2409
2509
  /** The address (host/port pair) of the pool */
2410
2510
  address: string;
2511
+ /* Excluded from this release type: name */
2411
2512
  /* Excluded from this release type: __constructor */
2412
2513
  }
2413
2514
 
@@ -2434,6 +2535,7 @@ export declare interface ConnectionPoolOptions extends Omit<ConnectionOptions, '
2434
2535
  * @category Event
2435
2536
  */
2436
2537
  export declare class ConnectionPoolReadyEvent extends ConnectionPoolMonitoringEvent {
2538
+ /* Excluded from this release type: name */
2437
2539
  /* Excluded from this release type: __constructor */
2438
2540
  }
2439
2541
 
@@ -2445,6 +2547,7 @@ export declare class ConnectionPoolReadyEvent extends ConnectionPoolMonitoringEv
2445
2547
  export declare class ConnectionReadyEvent extends ConnectionPoolMonitoringEvent {
2446
2548
  /** The id of the connection */
2447
2549
  connectionId: number | '<monitor>';
2550
+ /* Excluded from this release type: name */
2448
2551
  /* Excluded from this release type: __constructor */
2449
2552
  }
2450
2553
 
@@ -2635,6 +2738,22 @@ export declare class Db {
2635
2738
  * @remarks
2636
2739
  * This command does not inherit options from the MongoClient.
2637
2740
  *
2741
+ * The driver will ensure the following fields are attached to the command sent to the server:
2742
+ * - `lsid` - sourced from an implicit session or options.session
2743
+ * - `$readPreference` - defaults to primary or can be configured by options.readPreference
2744
+ * - `$db` - sourced from the name of this database
2745
+ *
2746
+ * If the client has a serverApi setting:
2747
+ * - `apiVersion`
2748
+ * - `apiStrict`
2749
+ * - `apiDeprecationErrors`
2750
+ *
2751
+ * When in a transaction:
2752
+ * - `readConcern` - sourced from readConcern set on the TransactionOptions
2753
+ * - `writeConcern` - sourced from writeConcern set on the TransactionOptions
2754
+ *
2755
+ * Attaching any of the above fields to the command will have no effect as the driver will overwrite the value.
2756
+ *
2638
2757
  * @param command - The command to run
2639
2758
  * @param options - Optional settings for the command
2640
2759
  */
@@ -2718,6 +2837,8 @@ export declare class Db {
2718
2837
  * @param username - The username for the new user
2719
2838
  * @param passwordOrOptions - An optional password for the new user, or the options for the command
2720
2839
  * @param options - Optional settings for the command
2840
+ * @deprecated Use the createUser command in `db.command()` instead.
2841
+ * @see https://www.mongodb.com/docs/manual/reference/command/createUser/
2721
2842
  */
2722
2843
  addUser(username: string, passwordOrOptions?: string | AddUserOptions, options?: AddUserOptions): Promise<Document>;
2723
2844
  /**
@@ -3591,6 +3712,30 @@ export declare class HostAddress {
3591
3712
  static fromString(this: void, s: string): HostAddress;
3592
3713
  static fromHostPort(host: string, port: number): HostAddress;
3593
3714
  static fromSrvRecord({ name, port }: SrvRecord): HostAddress;
3715
+ toHostPort(): {
3716
+ host: string;
3717
+ port: number;
3718
+ };
3719
+ }
3720
+
3721
+ /**
3722
+ * @public
3723
+ * @experimental
3724
+ */
3725
+ export declare interface IdPServerInfo {
3726
+ issuer: string;
3727
+ clientId: string;
3728
+ requestScopes?: string[];
3729
+ }
3730
+
3731
+ /**
3732
+ * @public
3733
+ * @experimental
3734
+ */
3735
+ export declare interface IdPServerResponse {
3736
+ accessToken: string;
3737
+ expiresInSeconds?: number;
3738
+ refreshToken?: string;
3594
3739
  }
3595
3740
 
3596
3741
  /** @public */
@@ -3877,6 +4022,13 @@ export declare interface ListIndexesOptions extends Omit<CommandOperationOptions
3877
4022
  batchSize?: number;
3878
4023
  }
3879
4024
 
4025
+ /* Excluded from this release type: Log */
4026
+
4027
+ /* Excluded from this release type: LogConvertible */
4028
+
4029
+ /* Excluded from this release type: Loggable */
4030
+
4031
+ /* Excluded from this release type: LoggableEvent */
3880
4032
  export { Long }
3881
4033
 
3882
4034
  /** @public */
@@ -4017,6 +4169,7 @@ export declare class MongoClient extends TypedEventEmitter<MongoClientEvents> {
4017
4169
  /* Excluded from this release type: connectionLock */
4018
4170
  /* Excluded from this release type: [kOptions] */
4019
4171
  constructor(url: string, options?: MongoClientOptions);
4172
+ /** @see MongoOptions */
4020
4173
  get options(): Readonly<MongoOptions>;
4021
4174
  get serverApi(): Readonly<ServerApi | undefined>;
4022
4175
  /* Excluded from this release type: monitorCommands */
@@ -4217,9 +4370,12 @@ export declare interface MongoClientOptions extends BSONSerializeOptions, Suppor
4217
4370
  sslCRL?: string;
4218
4371
  /** TCP Connection no delay */
4219
4372
  noDelay?: boolean;
4220
- /** TCP Connection keep alive enabled */
4373
+ /** @deprecated TCP Connection keep alive enabled. Will not be able to turn off in the future. */
4221
4374
  keepAlive?: boolean;
4222
- /** The number of milliseconds to wait before initiating keepAlive on the TCP socket */
4375
+ /**
4376
+ * @deprecated The number of milliseconds to wait before initiating keepAlive on the TCP socket.
4377
+ * Will not be configurable in the future.
4378
+ */
4223
4379
  keepAliveInitialDelay?: number;
4224
4380
  /** Force server to assign `_id` values instead of driver */
4225
4381
  forceServerObjectId?: boolean;
@@ -4306,7 +4462,7 @@ export declare class MongoCredentials {
4306
4462
 
4307
4463
  /** @public */
4308
4464
  export declare interface MongoCredentialsOptions {
4309
- username: string;
4465
+ username?: string;
4310
4466
  password: string;
4311
4467
  source: string;
4312
4468
  db?: string;
@@ -4337,6 +4493,8 @@ export declare class MongoCursorInUseError extends MongoAPIError {
4337
4493
  get name(): string;
4338
4494
  }
4339
4495
 
4496
+ /* Excluded from this release type: MongoDBLogWritable */
4497
+
4340
4498
  /** @public */
4341
4499
  export declare class MongoDBNamespace {
4342
4500
  db: string;
@@ -4560,7 +4718,22 @@ export declare class MongoNotConnectedError extends MongoAPIError {
4560
4718
  }
4561
4719
 
4562
4720
  /**
4563
- * Mongo Client Options
4721
+ * Parsed Mongo Client Options.
4722
+ *
4723
+ * User supplied options are documented by `MongoClientOptions`.
4724
+ *
4725
+ * **NOTE:** The client's options parsing is subject to change to support new features.
4726
+ * This type is provided to aid with inspection of options after parsing, it should not be relied upon programmatically.
4727
+ *
4728
+ * Options are sourced from:
4729
+ * - connection string
4730
+ * - options object passed to the MongoClient constructor
4731
+ * - file system (ex. tls settings)
4732
+ * - environment variables
4733
+ * - DNS SRV records and TXT records
4734
+ *
4735
+ * Not all options may be present after client construction as some are obtained from asynchronous operations.
4736
+ *
4564
4737
  * @public
4565
4738
  */
4566
4739
  export declare interface MongoOptions extends Required<Pick<MongoClientOptions, 'autoEncryption' | 'connectTimeoutMS' | 'directConnection' | 'driverInfo' | 'forceServerObjectId' | 'minHeartbeatFrequencyMS' | 'heartbeatFrequencyMS' | 'keepAlive' | 'keepAliveInitialDelay' | 'localThresholdMS' | 'maxConnecting' | 'maxIdleTimeMS' | 'maxPoolSize' | 'minPoolSize' | 'monitorCommands' | 'noDelay' | 'pkFactory' | 'raw' | 'replicaSet' | 'retryReads' | 'retryWrites' | 'serverSelectionTimeoutMS' | 'socketTimeoutMS' | 'srvMaxHosts' | 'srvServiceName' | 'tlsAllowInvalidCertificates' | 'tlsAllowInvalidHostnames' | 'tlsInsecure' | 'waitQueueTimeoutMS' | 'zlibCompressionLevel'>>, SupportedNodeConnectionOptions {
@@ -4833,36 +5006,24 @@ export { ObjectId }
4833
5006
  * @public
4834
5007
  * @experimental
4835
5008
  */
4836
- export declare interface OIDCMechanismServerStep1 {
4837
- authorizationEndpoint?: string;
4838
- tokenEndpoint?: string;
4839
- deviceAuthorizationEndpoint?: string;
4840
- clientId: string;
4841
- clientSecret?: string;
4842
- requestScopes?: string[];
5009
+ export declare interface OIDCCallbackContext {
5010
+ refreshToken?: string;
5011
+ timeoutSeconds?: number;
5012
+ timeoutContext?: AbortSignal;
5013
+ version: number;
4843
5014
  }
4844
5015
 
4845
5016
  /**
4846
5017
  * @public
4847
5018
  * @experimental
4848
5019
  */
4849
- export declare type OIDCRefreshFunction = (principalName: string, serverResult: OIDCMechanismServerStep1, result: OIDCRequestTokenResult, timeout: AbortSignal | number) => Promise<OIDCRequestTokenResult>;
5020
+ export declare type OIDCRefreshFunction = (info: IdPServerInfo, context: OIDCCallbackContext) => Promise<IdPServerResponse>;
4850
5021
 
4851
5022
  /**
4852
5023
  * @public
4853
5024
  * @experimental
4854
5025
  */
4855
- export declare type OIDCRequestFunction = (principalName: string, serverResult: OIDCMechanismServerStep1, timeout: AbortSignal | number) => Promise<OIDCRequestTokenResult>;
4856
-
4857
- /**
4858
- * @public
4859
- * @experimental
4860
- */
4861
- export declare interface OIDCRequestTokenResult {
4862
- accessToken: string;
4863
- expiresInSeconds?: number;
4864
- refreshToken?: string;
4865
- }
5026
+ export declare type OIDCRequestFunction = (info: IdPServerInfo, context: OIDCCallbackContext) => Promise<IdPServerResponse>;
4866
5027
 
4867
5028
  /** @public */
4868
5029
  export declare type OneOrMore<T> = T | ReadonlyArray<T>;
@@ -5208,7 +5369,10 @@ export declare const ReturnDocument: Readonly<{
5208
5369
  /** @public */
5209
5370
  export declare type ReturnDocument = (typeof ReturnDocument)[keyof typeof ReturnDocument];
5210
5371
 
5211
- /** @public */
5372
+ /**
5373
+ * @public
5374
+ * @deprecated Use the createUser command directly instead.
5375
+ */
5212
5376
  export declare interface RoleSpecification {
5213
5377
  /**
5214
5378
  * A role grants privileges to perform sets of actions on defined resources.
@@ -5239,7 +5403,37 @@ export declare interface RootFilterOperators<TSchema> extends Document {
5239
5403
  /* Excluded from this release type: RTTPingerOptions */
5240
5404
 
5241
5405
  /** @public */
5242
- export declare type RunCommandOptions = CommandOperationOptions;
5406
+ export declare type RunCommandOptions = {
5407
+ /** Specify ClientSession for this command */
5408
+ session?: ClientSession;
5409
+ /** The read preference */
5410
+ readPreference?: ReadPreferenceLike;
5411
+ /** @deprecated This is an internal option that has undefined behavior for this API */
5412
+ willRetryWrite?: any;
5413
+ /** @deprecated This is an internal option that has undefined behavior for this API */
5414
+ omitReadPreference?: any;
5415
+ /** @deprecated This is an internal option that has undefined behavior for this API */
5416
+ writeConcern?: any;
5417
+ /** @deprecated This is an internal option that has undefined behavior for this API */
5418
+ explain?: any;
5419
+ /** @deprecated This is an internal option that has undefined behavior for this API */
5420
+ readConcern?: any;
5421
+ /** @deprecated This is an internal option that has undefined behavior for this API */
5422
+ collation?: any;
5423
+ /** @deprecated This is an internal option that has undefined behavior for this API */
5424
+ maxTimeMS?: any;
5425
+ /** @deprecated This is an internal option that has undefined behavior for this API */
5426
+ comment?: any;
5427
+ /** @deprecated This is an internal option that has undefined behavior for this API */
5428
+ retryWrites?: any;
5429
+ /** @deprecated This is an internal option that has undefined behavior for this API */
5430
+ dbName?: any;
5431
+ /** @deprecated This is an internal option that has undefined behavior for this API */
5432
+ authdb?: any;
5433
+ /** @deprecated This is an internal option that has undefined behavior for this API */
5434
+ noResponse?: any;
5435
+ /* Excluded from this release type: bypassPinningCheck */
5436
+ } & BSONSerializeOptions;
5243
5437
 
5244
5438
  /** @public */
5245
5439
  export declare type SchemaMember<T, V> = {
@@ -5969,8 +6163,11 @@ export declare interface UpdateOptions extends CommandOperationOptions {
5969
6163
  let?: Document;
5970
6164
  }
5971
6165
 
5972
- /** @public */
5973
- export declare interface UpdateResult {
6166
+ /**
6167
+ * @public
6168
+ * `TSchema` is the schema of the collection
6169
+ */
6170
+ export declare interface UpdateResult<TSchema extends Document = Document> {
5974
6171
  /** Indicates whether this write result was acknowledged. If not, then all other members of this result will be undefined */
5975
6172
  acknowledged: boolean;
5976
6173
  /** The number of documents that matched the filter */
@@ -5980,7 +6177,7 @@ export declare interface UpdateResult {
5980
6177
  /** The number of documents that were upserted */
5981
6178
  upsertedCount: number;
5982
6179
  /** The identifier of the inserted document if an upsert took place */
5983
- upsertedId: ObjectId;
6180
+ upsertedId: InferIdType<TSchema> | null;
5984
6181
  }
5985
6182
 
5986
6183
  /** @public */
@@ -6012,7 +6209,10 @@ export declare type W = number | 'majority';
6012
6209
 
6013
6210
  /* Excluded from this release type: WaitQueueMember */
6014
6211
 
6015
- /** @public */
6212
+ /**
6213
+ * @public
6214
+ * @deprecated This type is only used for the deprecated `collStats` operation and will be removed in the next major release.
6215
+ */
6016
6216
  export declare interface WiredTigerData extends Document {
6017
6217
  LSM: {
6018
6218
  'bloom filter false positives': number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mongodb",
3
- "version": "5.2.0",
3
+ "version": "5.4.0",
4
4
  "description": "The official MongoDB driver for Node.js",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "peerDependencies": {
36
36
  "@aws-sdk/credential-providers": "^3.201.0",
37
- "mongodb-client-encryption": "^2.3.0",
37
+ "mongodb-client-encryption": ">=2.3.0 <3",
38
38
  "snappy": "^7.2.2"
39
39
  },
40
40
  "peerDependenciesMeta": {
@@ -127,7 +127,7 @@
127
127
  "check:atlas": "mocha --config test/manual/mocharc.json test/manual/atlas_connectivity.test.js",
128
128
  "check:adl": "mocha --config test/mocha_mongodb.json test/manual/atlas-data-lake-testing",
129
129
  "check:aws": "nyc mocha --config test/mocha_mongodb.json test/integration/auth/mongodb_aws.test.ts",
130
- "check:oidc": "mocha --config test/manual/mocharc.json test/manual/mongodb_oidc.prose.test.ts",
130
+ "check:oidc": "mocha --config test/mocha_mongodb.json test/manual/mongodb_oidc.prose.test.ts",
131
131
  "check:ocsp": "mocha --config test/manual/mocharc.json test/manual/ocsp_support.test.js",
132
132
  "check:kerberos": "nyc mocha --config test/manual/mocharc.json test/manual/kerberos.test.ts",
133
133
  "check:tls": "mocha --config test/manual/mocharc.json test/manual/tls_support.test.js",
package/src/admin.ts CHANGED
@@ -54,6 +54,22 @@ export class Admin {
54
54
  /**
55
55
  * Execute a command
56
56
  *
57
+ * The driver will ensure the following fields are attached to the command sent to the server:
58
+ * - `lsid` - sourced from an implicit session or options.session
59
+ * - `$readPreference` - defaults to primary or can be configured by options.readPreference
60
+ * - `$db` - sourced from the name of this database
61
+ *
62
+ * If the client has a serverApi setting:
63
+ * - `apiVersion`
64
+ * - `apiStrict`
65
+ * - `apiDeprecationErrors`
66
+ *
67
+ * When in a transaction:
68
+ * - `readConcern` - sourced from readConcern set on the TransactionOptions
69
+ * - `writeConcern` - sourced from writeConcern set on the TransactionOptions
70
+ *
71
+ * Attaching any of the above fields to the command will have no effect as the driver will overwrite the value.
72
+ *
57
73
  * @param command - The command to execute
58
74
  * @param options - Optional settings for the command
59
75
  */
@@ -106,6 +122,8 @@ export class Admin {
106
122
  * @param username - The username for the new user
107
123
  * @param passwordOrOptions - An optional password for the new user, or the options for the command
108
124
  * @param options - Optional settings for the command
125
+ * @deprecated Use the createUser command in `db.command()` instead.
126
+ * @see https://www.mongodb.com/docs/manual/reference/command/createUser/
109
127
  */
110
128
  async addUser(
111
129
  username: string,