mongodb 6.20.0-dev.20251008.sha.cfbada66 → 6.20.0-dev.20251010.sha.c5f74abe

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 (41) hide show
  1. package/lib/change_stream.js +5 -4
  2. package/lib/change_stream.js.map +1 -1
  3. package/lib/cmap/connect.js +1 -1
  4. package/lib/cmap/connect.js.map +1 -1
  5. package/lib/cmap/connection.js.map +1 -1
  6. package/lib/cmap/connection_pool.js +4 -4
  7. package/lib/cmap/connection_pool.js.map +1 -1
  8. package/lib/cmap/handshake/client_metadata.js +7 -5
  9. package/lib/cmap/handshake/client_metadata.js.map +1 -1
  10. package/lib/cursor/abstract_cursor.js +5 -4
  11. package/lib/cursor/abstract_cursor.js.map +1 -1
  12. package/lib/index.js +2 -4
  13. package/lib/index.js.map +1 -1
  14. package/lib/mongo_client.js +34 -27
  15. package/lib/mongo_client.js.map +1 -1
  16. package/lib/operations/aggregate.js +0 -3
  17. package/lib/operations/aggregate.js.map +1 -1
  18. package/lib/sdam/topology.js +1 -4
  19. package/lib/sdam/topology.js.map +1 -1
  20. package/lib/sessions.js +5 -4
  21. package/lib/sessions.js.map +1 -1
  22. package/mongodb.d.ts +58 -82
  23. package/package.json +2 -3
  24. package/src/change_stream.ts +1 -7
  25. package/src/cmap/connect.ts +1 -1
  26. package/src/cmap/connection.ts +1 -2
  27. package/src/cmap/connection_pool.ts +4 -4
  28. package/src/cmap/handshake/client_metadata.ts +18 -13
  29. package/src/cursor/abstract_cursor.ts +1 -7
  30. package/src/index.ts +0 -2
  31. package/src/mongo_client.ts +38 -62
  32. package/src/operations/aggregate.ts +0 -6
  33. package/src/sdam/topology.ts +2 -7
  34. package/src/sessions.ts +1 -7
  35. package/lib/beta.d.ts +0 -9094
  36. package/lib/beta.js +0 -21
  37. package/lib/beta.js.map +0 -1
  38. package/lib/resource_management.js +0 -58
  39. package/lib/resource_management.js.map +0 -1
  40. package/src/beta.ts +0 -22
  41. package/src/resource_management.ts +0 -74
@@ -16,7 +16,6 @@ import { AuthMechanism } from './cmap/auth/providers';
16
16
  import type { LEGAL_TCP_SOCKET_OPTIONS, LEGAL_TLS_SOCKET_OPTIONS } from './cmap/connect';
17
17
  import type { Connection } from './cmap/connection';
18
18
  import {
19
- addContainerMetadata,
20
19
  type ClientMetadata,
21
20
  isDriverInfoEqual,
22
21
  makeClientMetadata
@@ -48,7 +47,6 @@ import { executeOperation } from './operations/execute_operation';
48
47
  import { AbstractOperation } from './operations/operation';
49
48
  import type { ReadConcern, ReadConcernLevel, ReadConcernLike } from './read_concern';
50
49
  import { ReadPreference, type ReadPreferenceMode } from './read_preference';
51
- import { type AsyncDisposable, configureResourceManagement } from './resource_management';
52
50
  import type { ServerMonitoringMode } from './sdam/monitor';
53
51
  import type { TagSet } from './sdam/server_description';
54
52
  import { readPreferenceServerSelector } from './sdam/server_selection';
@@ -408,31 +406,12 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
408
406
  * The consolidate, parsed, transformed and merged options.
409
407
  */
410
408
  public readonly options: Readonly<
411
- Omit<
412
- MongoOptions,
413
- | 'monitorCommands'
414
- | 'ca'
415
- | 'crl'
416
- | 'key'
417
- | 'cert'
418
- | 'driverInfo'
419
- | 'additionalDriverInfo'
420
- | 'metadata'
421
- | 'extendedMetadata'
422
- >
409
+ Omit<MongoOptions, 'monitorCommands' | 'ca' | 'crl' | 'key' | 'cert' | 'driverInfo'>
423
410
  > &
424
- Pick<
425
- MongoOptions,
426
- | 'monitorCommands'
427
- | 'ca'
428
- | 'crl'
429
- | 'key'
430
- | 'cert'
431
- | 'driverInfo'
432
- | 'additionalDriverInfo'
433
- | 'metadata'
434
- | 'extendedMetadata'
435
- >;
411
+ Pick<MongoOptions, 'monitorCommands' | 'ca' | 'crl' | 'key' | 'cert' | 'driverInfo'> & {
412
+ /** @internal */
413
+ metadata: Promise<ClientMetadata>;
414
+ };
436
415
 
437
416
  private driverInfoList: DriverInfo[] = [];
438
417
 
@@ -485,13 +464,10 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
485
464
  }
486
465
 
487
466
  /**
488
- * @beta
489
467
  * @experimental
490
468
  * An alias for {@link MongoClient.close|MongoClient.close()}.
491
469
  */
492
- declare [Symbol.asyncDispose]: () => Promise<void>;
493
- /** @internal */
494
- async asyncDispose() {
470
+ async [Symbol.asyncDispose]() {
495
471
  await this.close();
496
472
  }
497
473
 
@@ -506,10 +482,9 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
506
482
  if (isDuplicateDriverInfo) return;
507
483
 
508
484
  this.driverInfoList.push(driverInfo);
509
- this.options.metadata = makeClientMetadata(this.driverInfoList, this.options);
510
- this.options.extendedMetadata = addContainerMetadata(this.options.metadata)
485
+ this.options.metadata = makeClientMetadata(this.driverInfoList, this.options)
511
486
  .then(undefined, squashError)
512
- .then(result => result ?? {}); // ensure Promise<Document>
487
+ .then(result => result ?? ({} as ClientMetadata)); // ensure Promise<Document>
513
488
  }
514
489
 
515
490
  /** @internal */
@@ -594,20 +569,13 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
594
569
  }
595
570
 
596
571
  /**
597
- * Connect to MongoDB using a url
572
+ * An optional method to verify a handful of assumptions that are generally useful at application boot-time before using a MongoClient.
573
+ * For detailed information about the connect process see the MongoClient.connect static method documentation.
598
574
  *
599
- * @remarks
600
- * Calling `connect` is optional since the first operation you perform will call `connect` if it's needed.
601
- * `timeoutMS` will bound the time any operation can take before throwing a timeout error.
602
- * However, when the operation being run is automatically connecting your `MongoClient` the `timeoutMS` will not apply to the time taken to connect the MongoClient.
603
- * This means the time to setup the `MongoClient` does not count against `timeoutMS`.
604
- * If you are using `timeoutMS` we recommend connecting your client explicitly in advance of any operation to avoid this inconsistent execution time.
605
- *
606
- * @remarks
607
- * The driver will look up corresponding SRV and TXT records if the connection string starts with `mongodb+srv://`.
608
- * If those look ups throw a DNS Timeout error, the driver will retry the look up once.
575
+ * @param url - The MongoDB connection string (supports `mongodb://` and `mongodb+srv://` schemes)
576
+ * @param options - Optional configuration options for the client
609
577
  *
610
- * @see docs.mongodb.org/manual/reference/connection-string/
578
+ * @see https://www.mongodb.com/docs/manual/reference/connection-string/
611
579
  */
612
580
  async connect(): Promise<this> {
613
581
  if (this.connectionLock) {
@@ -868,21 +836,35 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
868
836
  }
869
837
 
870
838
  /**
871
- * Connect to MongoDB using a url
839
+ * Creates a new MongoClient instance and immediately connects it to MongoDB.
840
+ * This convenience method combines `new MongoClient(url, options)` and `client.connect()` in a single step.
841
+ *
842
+ * Connect can be helpful to detect configuration issues early by validating:
843
+ * - **DNS Resolution**: Verifies that SRV records and hostnames in the connection string resolve DNS entries
844
+ * - **Network Connectivity**: Confirms that host addresses are reachable and ports are open
845
+ * - **TLS Configuration**: Validates SSL/TLS certificates, CA files, and encryption settings are correct
846
+ * - **Authentication**: Verifies that provided credentials are valid
847
+ * - **Server Compatibility**: Ensures the MongoDB server version is supported by this driver version
848
+ * - **Load Balancer Setup**: For load-balanced deployments, confirms the service is properly configured
849
+ *
850
+ * @returns A promise that resolves to the same MongoClient instance once connected
872
851
  *
873
852
  * @remarks
874
- * Calling `connect` is optional since the first operation you perform will call `connect` if it's needed.
875
- * `timeoutMS` will bound the time any operation can take before throwing a timeout error.
876
- * However, when the operation being run is automatically connecting your `MongoClient` the `timeoutMS` will not apply to the time taken to connect the MongoClient.
877
- * This means the time to setup the `MongoClient` does not count against `timeoutMS`.
878
- * If you are using `timeoutMS` we recommend connecting your client explicitly in advance of any operation to avoid this inconsistent execution time.
853
+ * **Connection is Optional:** Calling `connect` is optional since any operation method (`find`, `insertOne`, etc.)
854
+ * will automatically perform these same validation steps if the client is not already connected.
855
+ * However, explicitly calling `connect` can make sense for:
856
+ * - **Fail-fast Error Detection**: Non-transient connection issues (hostname unresolved, port refused connection) are discovered immediately rather than during your first operation
857
+ * - **Predictable Performance**: Eliminates first connection overhead from your first database operation
879
858
  *
880
859
  * @remarks
881
- * The programmatically provided options take precedence over the URI options.
860
+ * **Connection Pooling Impact:** Calling `connect` will populate the connection pool with one connection
861
+ * to a server selected by the client's configured `readPreference` (defaults to primary).
882
862
  *
883
863
  * @remarks
884
- * The driver will look up corresponding SRV and TXT records if the connection string starts with `mongodb+srv://`.
885
- * If those look ups throw a DNS Timeout error, the driver will retry the look up once.
864
+ * **Timeout Behavior:** When using `timeoutMS`, the connection establishment time does not count against
865
+ * the timeout for subsequent operations. This means `connect` runs without a `timeoutMS` limit, while
866
+ * your database operations will still respect the configured timeout. If you need predictable operation
867
+ * timing with `timeoutMS`, call `connect` explicitly before performing operations.
886
868
  *
887
869
  * @see https://www.mongodb.com/docs/manual/reference/connection-string/
888
870
  */
@@ -1037,8 +1019,6 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
1037
1019
  }
1038
1020
  }
1039
1021
 
1040
- configureResourceManagement(MongoClient.prototype);
1041
-
1042
1022
  /**
1043
1023
  * Parsed Mongo Client Options.
1044
1024
  *
@@ -1105,12 +1085,8 @@ export interface MongoOptions
1105
1085
  compressors: CompressorName[];
1106
1086
  writeConcern: WriteConcern;
1107
1087
  dbName: string;
1108
- /** @deprecated - Will be made internal in a future major release. */
1109
- metadata: ClientMetadata;
1110
- /** @deprecated - Will be made internal in a future major release. */
1111
- extendedMetadata: Promise<Document>;
1112
- /** @deprecated - Will be made internal in a future major release. */
1113
- additionalDriverInfo: DriverInfo[];
1088
+ /** @internal */
1089
+ metadata: Promise<ClientMetadata>;
1114
1090
  /** @internal */
1115
1091
  autoEncrypter?: AutoEncrypter;
1116
1092
  /** @internal */
@@ -80,12 +80,6 @@ export class AggregateOperation extends CommandOperation<CursorResponse> {
80
80
  delete this.options.writeConcern;
81
81
  }
82
82
 
83
- if (this.explain && this.writeConcern) {
84
- throw new MongoInvalidArgumentError(
85
- 'Option "explain" cannot be used on an aggregate call with writeConcern'
86
- );
87
- }
88
-
89
83
  if (options?.cursor != null && typeof options.cursor !== 'object') {
90
84
  throw new MongoInvalidArgumentError('Cursor options must be an object');
91
85
  }
@@ -150,8 +150,7 @@ export interface TopologyOptions extends BSONSerializeOptions, ServerOptions {
150
150
  /** Indicates that a client should directly connect to a node without attempting to discover its topology type */
151
151
  directConnection: boolean;
152
152
  loadBalanced: boolean;
153
- metadata: ClientMetadata;
154
- extendedMetadata: Promise<Document>;
153
+ metadata: Promise<ClientMetadata>;
155
154
  serverMonitoringMode: ServerMonitoringMode;
156
155
  /** MongoDB server API version */
157
156
  serverApi?: ServerApi;
@@ -466,7 +465,7 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
466
465
  );
467
466
 
468
467
  const skipPingOnConnect = this.s.options.__skipPingOnConnect === true;
469
- if (!skipPingOnConnect && this.s.credentials) {
468
+ if (!skipPingOnConnect) {
470
469
  const connection = await server.pool.checkOut({ timeoutContext: timeoutContext });
471
470
  server.pool.checkIn(connection);
472
471
  stateTransition(this, STATE_CONNECTED);
@@ -750,10 +749,6 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
750
749
  if (typeof callback === 'function') callback(undefined, true);
751
750
  }
752
751
 
753
- get clientMetadata(): ClientMetadata {
754
- return this.s.options.metadata;
755
- }
756
-
757
752
  isConnected(): boolean {
758
753
  return this.s.state === STATE_CONNECTED;
759
754
  }
package/src/sessions.ts CHANGED
@@ -26,7 +26,6 @@ import { executeOperation } from './operations/execute_operation';
26
26
  import { RunCommandOperation } from './operations/run_command';
27
27
  import { ReadConcernLevel } from './read_concern';
28
28
  import { ReadPreference } from './read_preference';
29
- import { type AsyncDisposable, configureResourceManagement } from './resource_management';
30
29
  import { _advanceClusterTime, type ClusterTime, TopologyType } from './sdam/common';
31
30
  import { TimeoutContext } from './timeout';
32
31
  import {
@@ -289,13 +288,10 @@ export class ClientSession
289
288
  }
290
289
  }
291
290
  /**
292
- * @beta
293
291
  * @experimental
294
292
  * An alias for {@link ClientSession.endSession|ClientSession.endSession()}.
295
293
  */
296
- declare [Symbol.asyncDispose]: () => Promise<void>;
297
- /** @internal */
298
- async asyncDispose() {
294
+ async [Symbol.asyncDispose]() {
299
295
  await this.endSession({ force: true });
300
296
  }
301
297
 
@@ -823,8 +819,6 @@ export class ClientSession
823
819
  }
824
820
  }
825
821
 
826
- configureResourceManagement(ClientSession.prototype);
827
-
828
822
  const NON_DETERMINISTIC_WRITE_CONCERN_ERRORS = new Set([
829
823
  'CannotSatisfyWriteConcern',
830
824
  'UnknownReplWriteConcern',