mongodb 6.20.0 → 7.0.0-dev.20251107.sha.5db818c2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -18
- package/lib/bulk/common.js +7 -9
- package/lib/bulk/common.js.map +1 -1
- package/lib/change_stream.js +84 -38
- package/lib/change_stream.js.map +1 -1
- package/lib/client-side-encryption/auto_encrypter.js +2 -4
- package/lib/client-side-encryption/auto_encrypter.js.map +1 -1
- package/lib/client-side-encryption/client_encryption.js +2 -3
- package/lib/client-side-encryption/client_encryption.js.map +1 -1
- package/lib/client-side-encryption/errors.js +3 -1
- package/lib/client-side-encryption/errors.js.map +1 -1
- package/lib/client-side-encryption/mongocryptd_manager.js +1 -1
- package/lib/client-side-encryption/mongocryptd_manager.js.map +1 -1
- package/lib/cmap/auth/aws_temporary_credentials.js +10 -58
- package/lib/cmap/auth/aws_temporary_credentials.js.map +1 -1
- package/lib/cmap/auth/mongo_credentials.js +0 -15
- package/lib/cmap/auth/mongo_credentials.js.map +1 -1
- package/lib/cmap/auth/mongodb_aws.js +2 -7
- package/lib/cmap/auth/mongodb_aws.js.map +1 -1
- package/lib/cmap/auth/providers.js +0 -1
- package/lib/cmap/auth/providers.js.map +1 -1
- package/lib/cmap/connect.js +1 -1
- package/lib/cmap/connect.js.map +1 -1
- package/lib/cmap/connection.js +28 -27
- package/lib/cmap/connection.js.map +1 -1
- package/lib/cmap/connection_pool.js +59 -59
- package/lib/cmap/connection_pool.js.map +1 -1
- package/lib/cmap/errors.js +1 -1
- package/lib/cmap/errors.js.map +1 -1
- package/lib/cmap/handshake/client_metadata.js +7 -5
- package/lib/cmap/handshake/client_metadata.js.map +1 -1
- package/lib/cmap/metrics.js +3 -3
- package/lib/cmap/metrics.js.map +1 -1
- package/lib/cmap/wire_protocol/constants.js +3 -1
- package/lib/cmap/wire_protocol/constants.js.map +1 -1
- package/lib/cmap/wire_protocol/on_data.js +0 -1
- package/lib/cmap/wire_protocol/on_data.js.map +1 -1
- package/lib/cmap/wire_protocol/responses.js +2 -2
- package/lib/cmap/wire_protocol/responses.js.map +1 -1
- package/lib/collection.js +1 -1
- package/lib/collection.js.map +1 -1
- package/lib/connection_string.js +8 -10
- package/lib/connection_string.js.map +1 -1
- package/lib/cursor/abstract_cursor.js +17 -34
- package/lib/cursor/abstract_cursor.js.map +1 -1
- package/lib/cursor/change_stream_cursor.js +2 -2
- package/lib/cursor/change_stream_cursor.js.map +1 -1
- package/lib/cursor/find_cursor.js +37 -26
- package/lib/cursor/find_cursor.js.map +1 -1
- package/lib/cursor/run_command_cursor.js +1 -1
- package/lib/cursor/run_command_cursor.js.map +1 -1
- package/lib/db.js +6 -6
- package/lib/db.js.map +1 -1
- package/lib/error.js +2 -2
- package/lib/error.js.map +1 -1
- package/lib/gridfs/download.js +5 -5
- package/lib/gridfs/download.js.map +1 -1
- package/lib/gridfs/index.js +9 -9
- package/lib/gridfs/index.js.map +1 -1
- package/lib/gridfs/upload.js +2 -8
- package/lib/gridfs/upload.js.map +1 -1
- package/lib/index.js +2 -4
- package/lib/index.js.map +1 -1
- package/lib/mongo_client.js +58 -67
- package/lib/mongo_client.js.map +1 -1
- package/lib/mongo_client_auth_providers.js +0 -6
- package/lib/mongo_client_auth_providers.js.map +1 -1
- package/lib/mongo_logger.js.map +1 -1
- package/lib/mongo_types.js +1 -2
- package/lib/mongo_types.js.map +1 -1
- package/lib/operations/aggregate.js +0 -3
- package/lib/operations/aggregate.js.map +1 -1
- package/lib/operations/command.js.map +1 -1
- package/lib/operations/create_collection.js +0 -1
- package/lib/operations/create_collection.js.map +1 -1
- package/lib/operations/drop.js +8 -9
- package/lib/operations/drop.js.map +1 -1
- package/lib/operations/end_sessions.js +34 -0
- package/lib/operations/end_sessions.js.map +1 -0
- package/lib/operations/execute_operation.js +3 -1
- package/lib/operations/execute_operation.js.map +1 -1
- package/lib/operations/find.js.map +1 -1
- package/lib/read_preference.js +10 -14
- package/lib/read_preference.js.map +1 -1
- package/lib/sdam/server.js +14 -14
- package/lib/sdam/server.js.map +1 -1
- package/lib/sdam/srv_polling.js +2 -2
- package/lib/sdam/srv_polling.js.map +1 -1
- package/lib/sdam/topology.js +24 -68
- package/lib/sdam/topology.js.map +1 -1
- package/lib/sessions.js +5 -4
- package/lib/sessions.js.map +1 -1
- package/lib/transactions.js +2 -13
- package/lib/transactions.js.map +1 -1
- package/lib/utils.js +0 -14
- package/lib/utils.js.map +1 -1
- package/mongodb.d.ts +72 -239
- package/package.json +17 -20
- package/src/bulk/common.ts +9 -11
- package/src/change_stream.ts +85 -37
- package/src/client-side-encryption/auto_encrypter.ts +6 -12
- package/src/client-side-encryption/client_encryption.ts +5 -6
- package/src/client-side-encryption/errors.ts +3 -0
- package/src/cmap/auth/aws_temporary_credentials.ts +12 -70
- package/src/cmap/auth/mongo_credentials.ts +1 -20
- package/src/cmap/auth/mongodb_aws.ts +8 -17
- package/src/cmap/auth/providers.ts +0 -1
- package/src/cmap/connect.ts +1 -1
- package/src/cmap/connection.ts +14 -16
- package/src/cmap/connection_pool.ts +4 -13
- package/src/cmap/errors.ts +1 -1
- package/src/cmap/handshake/client_metadata.ts +18 -26
- package/src/cmap/wire_protocol/constants.ts +2 -0
- package/src/cmap/wire_protocol/on_data.ts +1 -2
- package/src/collection.ts +1 -1
- package/src/connection_string.ts +13 -20
- package/src/cursor/abstract_cursor.ts +12 -49
- package/src/cursor/change_stream_cursor.ts +2 -2
- package/src/cursor/find_cursor.ts +40 -27
- package/src/cursor/run_command_cursor.ts +1 -1
- package/src/error.ts +2 -2
- package/src/gridfs/download.ts +0 -4
- package/src/gridfs/upload.ts +0 -22
- package/src/index.ts +2 -8
- package/src/mongo_client.ts +68 -100
- package/src/mongo_client_auth_providers.ts +0 -8
- package/src/mongo_logger.ts +1 -1
- package/src/mongo_types.ts +1 -2
- package/src/operations/aggregate.ts +0 -6
- package/src/operations/command.ts +0 -12
- package/src/operations/create_collection.ts +0 -3
- package/src/operations/drop.ts +9 -11
- package/src/operations/end_sessions.ts +44 -0
- package/src/operations/execute_operation.ts +6 -2
- package/src/operations/find.ts +2 -11
- package/src/read_preference.ts +0 -9
- package/src/sdam/topology.ts +2 -60
- package/src/sessions.ts +2 -8
- package/src/transactions.ts +2 -17
- package/src/utils.ts +0 -18
- package/tsconfig.json +5 -7
- package/lib/beta.d.ts +0 -9224
- package/lib/beta.js +0 -21
- package/lib/beta.js.map +0 -1
- package/lib/client-side-encryption/crypto_callbacks.js +0 -81
- package/lib/client-side-encryption/crypto_callbacks.js.map +0 -1
- package/lib/resource_management.js +0 -58
- package/lib/resource_management.js.map +0 -1
- package/src/beta.ts +0 -22
- package/src/client-side-encryption/crypto_callbacks.ts +0 -87
- package/src/resource_management.ts +0 -74
package/src/gridfs/download.ts
CHANGED
|
@@ -53,10 +53,6 @@ export interface GridFSFile {
|
|
|
53
53
|
filename: string;
|
|
54
54
|
metadata?: Document;
|
|
55
55
|
uploadDate: Date;
|
|
56
|
-
/** @deprecated Will be removed in the next major version. */
|
|
57
|
-
contentType?: string;
|
|
58
|
-
/** @deprecated Will be removed in the next major version. */
|
|
59
|
-
aliases?: string[];
|
|
60
56
|
}
|
|
61
57
|
|
|
62
58
|
/** @internal */
|
package/src/gridfs/upload.ts
CHANGED
|
@@ -32,16 +32,6 @@ export interface GridFSBucketWriteStreamOptions extends WriteConcernOptions {
|
|
|
32
32
|
id?: ObjectId;
|
|
33
33
|
/** Object to store in the file document's `metadata` field */
|
|
34
34
|
metadata?: Document;
|
|
35
|
-
/**
|
|
36
|
-
* String to store in the file document's `contentType` field.
|
|
37
|
-
* @deprecated Will be removed in the next major version. Add a contentType field to the metadata document instead.
|
|
38
|
-
*/
|
|
39
|
-
contentType?: string;
|
|
40
|
-
/**
|
|
41
|
-
* Array of strings to store in the file document's `aliases` field.
|
|
42
|
-
* @deprecated Will be removed in the next major version. Add an aliases field to the metadata document instead.
|
|
43
|
-
*/
|
|
44
|
-
aliases?: string[];
|
|
45
35
|
/**
|
|
46
36
|
* @experimental
|
|
47
37
|
* Specifies the time an operation will run until it throws a timeout error
|
|
@@ -305,8 +295,6 @@ function checkDone(stream: GridFSBucketWriteStream, callback: Callback): void {
|
|
|
305
295
|
stream.length,
|
|
306
296
|
stream.chunkSizeBytes,
|
|
307
297
|
stream.filename,
|
|
308
|
-
stream.options.contentType,
|
|
309
|
-
stream.options.aliases,
|
|
310
298
|
stream.options.metadata
|
|
311
299
|
);
|
|
312
300
|
|
|
@@ -402,8 +390,6 @@ function createFilesDoc(
|
|
|
402
390
|
length: number,
|
|
403
391
|
chunkSize: number,
|
|
404
392
|
filename: string,
|
|
405
|
-
contentType?: string,
|
|
406
|
-
aliases?: string[],
|
|
407
393
|
metadata?: Document
|
|
408
394
|
): GridFSFile {
|
|
409
395
|
const ret: GridFSFile = {
|
|
@@ -414,14 +400,6 @@ function createFilesDoc(
|
|
|
414
400
|
filename
|
|
415
401
|
};
|
|
416
402
|
|
|
417
|
-
if (contentType) {
|
|
418
|
-
ret.contentType = contentType;
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
if (aliases) {
|
|
422
|
-
ret.aliases = aliases;
|
|
423
|
-
}
|
|
424
|
-
|
|
425
403
|
if (metadata) {
|
|
426
404
|
ret.metadata = metadata;
|
|
427
405
|
}
|
package/src/index.ts
CHANGED
|
@@ -87,7 +87,6 @@ export {
|
|
|
87
87
|
MongoWriteConcernError,
|
|
88
88
|
WriteConcernErrorResult
|
|
89
89
|
} from './error';
|
|
90
|
-
export { configureExplicitResourceManagement } from './resource_management';
|
|
91
90
|
export {
|
|
92
91
|
AbstractCursor,
|
|
93
92
|
// Actual driver classes exported
|
|
@@ -224,7 +223,6 @@ export type {
|
|
|
224
223
|
ChangeStreamSplitEvent,
|
|
225
224
|
ChangeStreamUpdateDocument,
|
|
226
225
|
OperationTime,
|
|
227
|
-
ResumeOptions,
|
|
228
226
|
ResumeToken,
|
|
229
227
|
UpdateDescription
|
|
230
228
|
} from './change_stream';
|
|
@@ -307,7 +305,6 @@ export type {
|
|
|
307
305
|
ProxyOptions
|
|
308
306
|
} from './cmap/connection';
|
|
309
307
|
export type {
|
|
310
|
-
CloseOptions,
|
|
311
308
|
ConnectionPool,
|
|
312
309
|
ConnectionPoolEvents,
|
|
313
310
|
ConnectionPoolOptions,
|
|
@@ -315,7 +312,7 @@ export type {
|
|
|
315
312
|
WaitQueueMember,
|
|
316
313
|
WithConnectionCallback
|
|
317
314
|
} from './cmap/connection_pool';
|
|
318
|
-
export type { ClientMetadata
|
|
315
|
+
export type { ClientMetadata } from './cmap/handshake/client_metadata';
|
|
319
316
|
export type { ConnectionPoolMetrics } from './cmap/metrics';
|
|
320
317
|
export type { StreamDescription, StreamDescriptionOptions } from './cmap/stream_description';
|
|
321
318
|
export type { CompressorName } from './cmap/wire_protocol/compression';
|
|
@@ -368,8 +365,7 @@ export type {
|
|
|
368
365
|
export type {
|
|
369
366
|
AbstractCursorEvents,
|
|
370
367
|
AbstractCursorOptions,
|
|
371
|
-
CursorFlag
|
|
372
|
-
CursorStreamOptions
|
|
368
|
+
CursorFlag
|
|
373
369
|
} from './cursor/abstract_cursor';
|
|
374
370
|
export type {
|
|
375
371
|
CursorTimeoutContext,
|
|
@@ -566,7 +562,6 @@ export type {
|
|
|
566
562
|
ReadPreferenceLikeOptions,
|
|
567
563
|
ReadPreferenceOptions
|
|
568
564
|
} from './read_preference';
|
|
569
|
-
export type { AsyncDisposable } from './resource_management';
|
|
570
565
|
export type { ClusterTime } from './sdam/common';
|
|
571
566
|
export type {
|
|
572
567
|
Monitor,
|
|
@@ -598,7 +593,6 @@ export type { SrvPoller, SrvPollerEvents, SrvPollerOptions } from './sdam/srv_po
|
|
|
598
593
|
export type {
|
|
599
594
|
ConnectOptions,
|
|
600
595
|
SelectServerOptions,
|
|
601
|
-
ServerCapabilities,
|
|
602
596
|
ServerSelectionCallback,
|
|
603
597
|
ServerSelectionRequest,
|
|
604
598
|
Topology,
|
package/src/mongo_client.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { promises as fs } from 'fs';
|
|
|
2
2
|
import type { TcpNetConnectOpts } from 'net';
|
|
3
3
|
import type { ConnectionOptions as TLSConnectionOptions, TLSSocketOptions } from 'tls';
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { TopologyType } from '.';
|
|
6
6
|
import { type BSONSerializeOptions, type Document, resolveBSONOptions } from './bson';
|
|
7
7
|
import { ChangeStream, type ChangeStreamDocument, type ChangeStreamOptions } from './change_stream';
|
|
8
8
|
import type { AutoEncrypter, AutoEncryptionOptions } from './client-side-encryption/auto_encrypter';
|
|
@@ -16,13 +16,11 @@ 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
|
|
23
22
|
} from './cmap/handshake/client_metadata';
|
|
24
23
|
import type { CompressorName } from './cmap/wire_protocol/compression';
|
|
25
|
-
import { MongoDBResponse } from './cmap/wire_protocol/responses';
|
|
26
24
|
import { parseOptions, resolveSRVRecord } from './connection_string';
|
|
27
25
|
import { MONGO_CLIENT_EVENTS } from './constants';
|
|
28
26
|
import { type AbstractCursor } from './cursor/abstract_cursor';
|
|
@@ -44,11 +42,10 @@ import {
|
|
|
44
42
|
type ClientBulkWriteResult
|
|
45
43
|
} from './operations/client_bulk_write/common';
|
|
46
44
|
import { ClientBulkWriteExecutor } from './operations/client_bulk_write/executor';
|
|
45
|
+
import { EndSessionsOperation } from './operations/end_sessions';
|
|
47
46
|
import { executeOperation } from './operations/execute_operation';
|
|
48
|
-
import { AbstractOperation } from './operations/operation';
|
|
49
47
|
import type { ReadConcern, ReadConcernLevel, ReadConcernLike } from './read_concern';
|
|
50
48
|
import { ReadPreference, type ReadPreferenceMode } from './read_preference';
|
|
51
|
-
import { type AsyncDisposable, configureResourceManagement } from './resource_management';
|
|
52
49
|
import type { ServerMonitoringMode } from './sdam/monitor';
|
|
53
50
|
import type { TagSet } from './sdam/server_description';
|
|
54
51
|
import { readPreferenceServerSelector } from './sdam/server_selection';
|
|
@@ -63,7 +60,7 @@ import {
|
|
|
63
60
|
type HostAddress,
|
|
64
61
|
hostMatchesWildcards,
|
|
65
62
|
isHostMatch,
|
|
66
|
-
MongoDBNamespace,
|
|
63
|
+
type MongoDBNamespace,
|
|
67
64
|
noop,
|
|
68
65
|
ns,
|
|
69
66
|
resolveOptions,
|
|
@@ -408,31 +405,12 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
|
|
|
408
405
|
* The consolidate, parsed, transformed and merged options.
|
|
409
406
|
*/
|
|
410
407
|
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
|
-
>
|
|
408
|
+
Omit<MongoOptions, 'monitorCommands' | 'ca' | 'crl' | 'key' | 'cert' | 'driverInfo'>
|
|
423
409
|
> &
|
|
424
|
-
Pick<
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
| 'crl'
|
|
429
|
-
| 'key'
|
|
430
|
-
| 'cert'
|
|
431
|
-
| 'driverInfo'
|
|
432
|
-
| 'additionalDriverInfo'
|
|
433
|
-
| 'metadata'
|
|
434
|
-
| 'extendedMetadata'
|
|
435
|
-
>;
|
|
410
|
+
Pick<MongoOptions, 'monitorCommands' | 'ca' | 'crl' | 'key' | 'cert' | 'driverInfo'> & {
|
|
411
|
+
/** @internal */
|
|
412
|
+
metadata: Promise<ClientMetadata>;
|
|
413
|
+
};
|
|
436
414
|
|
|
437
415
|
private driverInfoList: DriverInfo[] = [];
|
|
438
416
|
|
|
@@ -485,13 +463,10 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
|
|
|
485
463
|
}
|
|
486
464
|
|
|
487
465
|
/**
|
|
488
|
-
* @beta
|
|
489
466
|
* @experimental
|
|
490
467
|
* An alias for {@link MongoClient.close|MongoClient.close()}.
|
|
491
468
|
*/
|
|
492
|
-
|
|
493
|
-
/** @internal */
|
|
494
|
-
async asyncDispose() {
|
|
469
|
+
async [Symbol.asyncDispose]() {
|
|
495
470
|
await this.close();
|
|
496
471
|
}
|
|
497
472
|
|
|
@@ -506,10 +481,9 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
|
|
|
506
481
|
if (isDuplicateDriverInfo) return;
|
|
507
482
|
|
|
508
483
|
this.driverInfoList.push(driverInfo);
|
|
509
|
-
this.options.metadata = makeClientMetadata(this.driverInfoList, this.options)
|
|
510
|
-
this.options.extendedMetadata = addContainerMetadata(this.options.metadata)
|
|
484
|
+
this.options.metadata = makeClientMetadata(this.driverInfoList, this.options)
|
|
511
485
|
.then(undefined, squashError)
|
|
512
|
-
.then(result => result ?? {}); // ensure Promise<Document>
|
|
486
|
+
.then(result => result ?? ({} as ClientMetadata)); // ensure Promise<Document>
|
|
513
487
|
}
|
|
514
488
|
|
|
515
489
|
/** @internal */
|
|
@@ -594,20 +568,13 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
|
|
|
594
568
|
}
|
|
595
569
|
|
|
596
570
|
/**
|
|
597
|
-
*
|
|
571
|
+
* An optional method to verify a handful of assumptions that are generally useful at application boot-time before using a MongoClient.
|
|
572
|
+
* For detailed information about the connect process see the MongoClient.connect static method documentation.
|
|
598
573
|
*
|
|
599
|
-
* @
|
|
600
|
-
*
|
|
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.
|
|
574
|
+
* @param url - The MongoDB connection string (supports `mongodb://` and `mongodb+srv://` schemes)
|
|
575
|
+
* @param options - Optional configuration options for the client
|
|
609
576
|
*
|
|
610
|
-
* @see
|
|
577
|
+
* @see https://www.mongodb.com/docs/manual/reference/connection-string/
|
|
611
578
|
*/
|
|
612
579
|
async connect(): Promise<this> {
|
|
613
580
|
if (this.connectionLock) {
|
|
@@ -795,40 +762,12 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
|
|
|
795
762
|
return;
|
|
796
763
|
}
|
|
797
764
|
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
if (servers.length !== 0) {
|
|
805
|
-
const endSessions = Array.from(this.s.sessionPool.sessions, ({ id }) => id);
|
|
806
|
-
if (endSessions.length !== 0) {
|
|
807
|
-
try {
|
|
808
|
-
class EndSessionsOperation extends AbstractOperation<void> {
|
|
809
|
-
override ns = MongoDBNamespace.fromString('admin.$cmd');
|
|
810
|
-
override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
|
|
811
|
-
override buildCommand(_connection: Connection, _session?: ClientSession): Document {
|
|
812
|
-
return {
|
|
813
|
-
endSessions
|
|
814
|
-
};
|
|
815
|
-
}
|
|
816
|
-
override buildOptions(timeoutContext: TimeoutContext): ServerCommandOptions {
|
|
817
|
-
return {
|
|
818
|
-
timeoutContext,
|
|
819
|
-
readPreference: ReadPreference.primaryPreferred,
|
|
820
|
-
noResponse: true
|
|
821
|
-
};
|
|
822
|
-
}
|
|
823
|
-
override get commandName(): string {
|
|
824
|
-
return 'endSessions';
|
|
825
|
-
}
|
|
826
|
-
}
|
|
827
|
-
await executeOperation(this, new EndSessionsOperation());
|
|
828
|
-
} catch (error) {
|
|
829
|
-
squashError(error);
|
|
830
|
-
}
|
|
831
|
-
}
|
|
765
|
+
const supportsSessions =
|
|
766
|
+
this.topology.description.type === TopologyType.LoadBalanced ||
|
|
767
|
+
this.topology.description.logicalSessionTimeoutMinutes != null;
|
|
768
|
+
|
|
769
|
+
if (supportsSessions) {
|
|
770
|
+
await endSessions(this, this.topology);
|
|
832
771
|
}
|
|
833
772
|
|
|
834
773
|
// clear out references to old topology
|
|
@@ -841,6 +780,27 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
|
|
|
841
780
|
if (encrypter) {
|
|
842
781
|
await encrypter.close(this);
|
|
843
782
|
}
|
|
783
|
+
|
|
784
|
+
async function endSessions(
|
|
785
|
+
client: MongoClient,
|
|
786
|
+
{ description: topologyDescription }: Topology
|
|
787
|
+
) {
|
|
788
|
+
// If we would attempt to select a server and get nothing back we short circuit
|
|
789
|
+
// to avoid the server selection timeout.
|
|
790
|
+
const selector = readPreferenceServerSelector(ReadPreference.primaryPreferred);
|
|
791
|
+
const serverDescriptions = Array.from(topologyDescription.servers.values());
|
|
792
|
+
const servers = selector(topologyDescription, serverDescriptions);
|
|
793
|
+
if (servers.length !== 0) {
|
|
794
|
+
const endSessions = Array.from(client.s.sessionPool.sessions, ({ id }) => id);
|
|
795
|
+
if (endSessions.length !== 0) {
|
|
796
|
+
try {
|
|
797
|
+
await executeOperation(client, new EndSessionsOperation(endSessions));
|
|
798
|
+
} catch (error) {
|
|
799
|
+
squashError(error);
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
}
|
|
844
804
|
}
|
|
845
805
|
|
|
846
806
|
/**
|
|
@@ -868,21 +828,35 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
|
|
|
868
828
|
}
|
|
869
829
|
|
|
870
830
|
/**
|
|
871
|
-
*
|
|
831
|
+
* Creates a new MongoClient instance and immediately connects it to MongoDB.
|
|
832
|
+
* This convenience method combines `new MongoClient(url, options)` and `client.connect()` in a single step.
|
|
833
|
+
*
|
|
834
|
+
* Connect can be helpful to detect configuration issues early by validating:
|
|
835
|
+
* - **DNS Resolution**: Verifies that SRV records and hostnames in the connection string resolve DNS entries
|
|
836
|
+
* - **Network Connectivity**: Confirms that host addresses are reachable and ports are open
|
|
837
|
+
* - **TLS Configuration**: Validates SSL/TLS certificates, CA files, and encryption settings are correct
|
|
838
|
+
* - **Authentication**: Verifies that provided credentials are valid
|
|
839
|
+
* - **Server Compatibility**: Ensures the MongoDB server version is supported by this driver version
|
|
840
|
+
* - **Load Balancer Setup**: For load-balanced deployments, confirms the service is properly configured
|
|
841
|
+
*
|
|
842
|
+
* @returns A promise that resolves to the same MongoClient instance once connected
|
|
872
843
|
*
|
|
873
844
|
* @remarks
|
|
874
|
-
* Calling `connect` is optional since
|
|
875
|
-
*
|
|
876
|
-
* However,
|
|
877
|
-
*
|
|
878
|
-
*
|
|
845
|
+
* **Connection is Optional:** Calling `connect` is optional since any operation method (`find`, `insertOne`, etc.)
|
|
846
|
+
* will automatically perform these same validation steps if the client is not already connected.
|
|
847
|
+
* However, explicitly calling `connect` can make sense for:
|
|
848
|
+
* - **Fail-fast Error Detection**: Non-transient connection issues (hostname unresolved, port refused connection) are discovered immediately rather than during your first operation
|
|
849
|
+
* - **Predictable Performance**: Eliminates first connection overhead from your first database operation
|
|
879
850
|
*
|
|
880
851
|
* @remarks
|
|
881
|
-
*
|
|
852
|
+
* **Connection Pooling Impact:** Calling `connect` will populate the connection pool with one connection
|
|
853
|
+
* to a server selected by the client's configured `readPreference` (defaults to primary).
|
|
882
854
|
*
|
|
883
855
|
* @remarks
|
|
884
|
-
*
|
|
885
|
-
*
|
|
856
|
+
* **Timeout Behavior:** When using `timeoutMS`, the connection establishment time does not count against
|
|
857
|
+
* the timeout for subsequent operations. This means `connect` runs without a `timeoutMS` limit, while
|
|
858
|
+
* your database operations will still respect the configured timeout. If you need predictable operation
|
|
859
|
+
* timing with `timeoutMS`, call `connect` explicitly before performing operations.
|
|
886
860
|
*
|
|
887
861
|
* @see https://www.mongodb.com/docs/manual/reference/connection-string/
|
|
888
862
|
*/
|
|
@@ -1037,8 +1011,6 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
|
|
|
1037
1011
|
}
|
|
1038
1012
|
}
|
|
1039
1013
|
|
|
1040
|
-
configureResourceManagement(MongoClient.prototype);
|
|
1041
|
-
|
|
1042
1014
|
/**
|
|
1043
1015
|
* Parsed Mongo Client Options.
|
|
1044
1016
|
*
|
|
@@ -1105,12 +1077,8 @@ export interface MongoOptions
|
|
|
1105
1077
|
compressors: CompressorName[];
|
|
1106
1078
|
writeConcern: WriteConcern;
|
|
1107
1079
|
dbName: string;
|
|
1108
|
-
/** @
|
|
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[];
|
|
1080
|
+
/** @internal */
|
|
1081
|
+
metadata: Promise<ClientMetadata>;
|
|
1114
1082
|
/** @internal */
|
|
1115
1083
|
autoEncrypter?: AutoEncrypter;
|
|
1116
1084
|
/** @internal */
|
|
@@ -21,14 +21,6 @@ const AUTH_PROVIDERS = new Map<
|
|
|
21
21
|
AuthMechanism.MONGODB_AWS,
|
|
22
22
|
({ AWS_CREDENTIAL_PROVIDER }) => new MongoDBAWS(AWS_CREDENTIAL_PROVIDER)
|
|
23
23
|
],
|
|
24
|
-
[
|
|
25
|
-
AuthMechanism.MONGODB_CR,
|
|
26
|
-
() => {
|
|
27
|
-
throw new MongoInvalidArgumentError(
|
|
28
|
-
'MONGODB-CR is no longer a supported auth mechanism in MongoDB 4.0+'
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
],
|
|
32
24
|
[AuthMechanism.MONGODB_GSSAPI, () => new GSSAPI()],
|
|
33
25
|
[AuthMechanism.MONGODB_OIDC, properties => new MongoDBOIDC(getWorkflow(properties))],
|
|
34
26
|
[AuthMechanism.MONGODB_PLAIN, () => new Plain()],
|
package/src/mongo_logger.ts
CHANGED
|
@@ -240,7 +240,7 @@ export function createStdioLogger(stream: {
|
|
|
240
240
|
write: NodeJS.WriteStream['write'];
|
|
241
241
|
}): MongoDBLogWritable {
|
|
242
242
|
return {
|
|
243
|
-
write: promisify((log: Log, cb: (error?: Error) => void): unknown => {
|
|
243
|
+
write: promisify((log: Log, cb: (error?: Error | null) => void): unknown => {
|
|
244
244
|
const logLine = inspect(log, { compact: true, breakLength: Infinity });
|
|
245
245
|
stream.write(`${logLine}\n`, 'utf-8', cb);
|
|
246
246
|
return;
|
package/src/mongo_types.ts
CHANGED
|
@@ -473,8 +473,7 @@ export class TypedEventEmitter<Events extends EventsDescription> extends EventEm
|
|
|
473
473
|
}
|
|
474
474
|
|
|
475
475
|
/**
|
|
476
|
-
* @
|
|
477
|
-
* @deprecated Will be removed in favor of `AbortSignal` in the next major release.
|
|
476
|
+
* @internal
|
|
478
477
|
*/
|
|
479
478
|
export class CancellationToken extends TypedEventEmitter<{ cancel(): void }> {
|
|
480
479
|
constructor(...args: any[]) {
|
|
@@ -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
|
}
|
|
@@ -53,21 +53,9 @@ export interface CommandOperationOptions
|
|
|
53
53
|
* In server versions 4.4 and above, 'comment' can be any valid BSON type.
|
|
54
54
|
*/
|
|
55
55
|
comment?: unknown;
|
|
56
|
-
/**
|
|
57
|
-
* @deprecated
|
|
58
|
-
* This option is deprecated and will be removed in a future release as it is not used
|
|
59
|
-
* in the driver. Use MongoClientOptions or connection string parameters instead.
|
|
60
|
-
* */
|
|
61
|
-
retryWrites?: boolean;
|
|
62
|
-
|
|
63
56
|
// Admin command overrides.
|
|
64
57
|
dbName?: string;
|
|
65
58
|
authdb?: string;
|
|
66
|
-
/**
|
|
67
|
-
* @deprecated
|
|
68
|
-
* This option is deprecated and will be removed in an upcoming major version.
|
|
69
|
-
*/
|
|
70
|
-
noResponse?: boolean;
|
|
71
59
|
|
|
72
60
|
/**
|
|
73
61
|
* Used when the command needs to grant access to the underlying namespaces for time series collections.
|
|
@@ -23,7 +23,6 @@ const ILLEGAL_COMMAND_FIELDS = new Set([
|
|
|
23
23
|
'timeoutMS',
|
|
24
24
|
'j',
|
|
25
25
|
'fsync',
|
|
26
|
-
'autoIndexId',
|
|
27
26
|
'pkFactory',
|
|
28
27
|
'raw',
|
|
29
28
|
'readPreference',
|
|
@@ -68,8 +67,6 @@ export interface ClusteredCollectionOptions extends Document {
|
|
|
68
67
|
export interface CreateCollectionOptions extends Omit<CommandOperationOptions, 'rawData'> {
|
|
69
68
|
/** Create a capped collection */
|
|
70
69
|
capped?: boolean;
|
|
71
|
-
/** @deprecated Create an index on the _id field of the document. This option is deprecated in MongoDB 3.2+ and will be removed once no longer supported by the server. */
|
|
72
|
-
autoIndexId?: boolean;
|
|
73
70
|
/** The size of the capped collection in bytes */
|
|
74
71
|
size?: number;
|
|
75
72
|
/** The maximum number of documents in the capped collection */
|
package/src/operations/drop.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Connection, MongoServerError } from '..';
|
|
1
|
+
import { type Connection, type MongoError, MongoServerError } from '..';
|
|
2
2
|
import type { Document } from '../bson';
|
|
3
3
|
import { MongoDBResponse } from '../cmap/wire_protocol/responses';
|
|
4
4
|
import { CursorTimeoutContext } from '../cursor/abstract_cursor';
|
|
@@ -40,6 +40,13 @@ export class DropCollectionOperation extends CommandOperation<boolean> {
|
|
|
40
40
|
override handleOk(_response: InstanceType<typeof this.SERVER_COMMAND_RESPONSE_TYPE>): boolean {
|
|
41
41
|
return true;
|
|
42
42
|
}
|
|
43
|
+
|
|
44
|
+
override handleError(error: MongoError): boolean {
|
|
45
|
+
if (!(error instanceof MongoServerError)) throw error;
|
|
46
|
+
if (Number(error.code) !== MONGODB_ERROR_CODES.NamespaceNotFound) throw error;
|
|
47
|
+
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
43
50
|
}
|
|
44
51
|
|
|
45
52
|
export async function dropCollections(
|
|
@@ -83,16 +90,7 @@ export async function dropCollections(
|
|
|
83
90
|
for (const collectionName of [escCollection, ecocCollection]) {
|
|
84
91
|
// Drop auxilliary collections, ignoring potential NamespaceNotFound errors.
|
|
85
92
|
const dropOp = new DropCollectionOperation(db, collectionName, options);
|
|
86
|
-
|
|
87
|
-
await executeOperation(db.client, dropOp, timeoutContext);
|
|
88
|
-
} catch (err) {
|
|
89
|
-
if (
|
|
90
|
-
!(err instanceof MongoServerError) ||
|
|
91
|
-
err.code !== MONGODB_ERROR_CODES.NamespaceNotFound
|
|
92
|
-
) {
|
|
93
|
-
throw err;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
93
|
+
await executeOperation(db.client, dropOp, timeoutContext);
|
|
96
94
|
}
|
|
97
95
|
}
|
|
98
96
|
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ClientSession,
|
|
3
|
+
type Connection,
|
|
4
|
+
type ServerCommandOptions,
|
|
5
|
+
type ServerSessionId,
|
|
6
|
+
type TimeoutContext,
|
|
7
|
+
type WriteConcern
|
|
8
|
+
} from '..';
|
|
9
|
+
import { type Document } from '../bson';
|
|
10
|
+
import { MongoDBResponse } from '../cmap/wire_protocol/responses';
|
|
11
|
+
import { CommandOperation } from '../operations/command';
|
|
12
|
+
import { ReadPreference } from '../read_preference';
|
|
13
|
+
import { MongoDBNamespace } from '../utils';
|
|
14
|
+
import { Aspect, defineAspects } from './operation';
|
|
15
|
+
|
|
16
|
+
export class EndSessionsOperation extends CommandOperation<void> {
|
|
17
|
+
override writeConcern: WriteConcern = { w: 0 };
|
|
18
|
+
override ns = MongoDBNamespace.fromString('admin.$cmd');
|
|
19
|
+
override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
|
|
20
|
+
|
|
21
|
+
private sessions: Array<ServerSessionId>;
|
|
22
|
+
|
|
23
|
+
constructor(sessions: Array<ServerSessionId>) {
|
|
24
|
+
super();
|
|
25
|
+
this.sessions = sessions;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
override buildCommandDocument(_connection: Connection, _session?: ClientSession): Document {
|
|
29
|
+
return {
|
|
30
|
+
endSessions: this.sessions
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
override buildOptions(timeoutContext: TimeoutContext): ServerCommandOptions {
|
|
34
|
+
return {
|
|
35
|
+
timeoutContext,
|
|
36
|
+
readPreference: ReadPreference.primaryPreferred
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
override get commandName(): string {
|
|
40
|
+
return 'endSessions';
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
defineAspects(EndSessionsOperation, Aspect.WRITE_OPERATION);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { MIN_SUPPORTED_SNAPSHOT_READS_WIRE_VERSION } from '../cmap/wire_protocol/constants';
|
|
1
2
|
import {
|
|
2
3
|
isRetryableReadError,
|
|
3
4
|
isRetryableWriteError,
|
|
@@ -25,7 +26,7 @@ import {
|
|
|
25
26
|
import type { Topology } from '../sdam/topology';
|
|
26
27
|
import type { ClientSession } from '../sessions';
|
|
27
28
|
import { TimeoutContext } from '../timeout';
|
|
28
|
-
import { abortable, supportsRetryableWrites } from '../utils';
|
|
29
|
+
import { abortable, maxWireVersion, supportsRetryableWrites } from '../utils';
|
|
29
30
|
import { AggregateOperation } from './aggregate';
|
|
30
31
|
import { AbstractOperation, Aspect } from './operation';
|
|
31
32
|
|
|
@@ -81,7 +82,10 @@ export async function executeOperation<
|
|
|
81
82
|
session = client.startSession({ owner, explicit: false });
|
|
82
83
|
} else if (session.hasEnded) {
|
|
83
84
|
throw new MongoExpiredSessionError('Use of expired sessions is not permitted');
|
|
84
|
-
} else if (
|
|
85
|
+
} else if (
|
|
86
|
+
session.snapshotEnabled &&
|
|
87
|
+
maxWireVersion(topology) < MIN_SUPPORTED_SNAPSHOT_READS_WIRE_VERSION
|
|
88
|
+
) {
|
|
85
89
|
throw new MongoCompatibilityError('Snapshot reads require MongoDB 5.0 or later');
|
|
86
90
|
} else if (session.client !== client) {
|
|
87
91
|
throw new MongoInvalidArgumentError('ClientSession must be from the same MongoClient');
|
package/src/operations/find.ts
CHANGED
|
@@ -12,10 +12,8 @@ import { Aspect, defineAspects, type Hint } from './operation';
|
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* @public
|
|
15
|
-
* @typeParam TSchema - Unused schema definition, deprecated usage, only specify `FindOptions` with no generic
|
|
16
15
|
*/
|
|
17
|
-
|
|
18
|
-
export interface FindOptions<TSchema extends Document = Document>
|
|
16
|
+
export interface FindOptions
|
|
19
17
|
extends Omit<CommandOperationOptions, 'writeConcern' | 'explain'>,
|
|
20
18
|
AbstractCursorOptions {
|
|
21
19
|
/** Sets the limit of documents returned in the query. */
|
|
@@ -76,14 +74,7 @@ export interface FindOptions<TSchema extends Document = Document>
|
|
|
76
74
|
}
|
|
77
75
|
|
|
78
76
|
/** @public */
|
|
79
|
-
export
|
|
80
|
-
/** @deprecated Will be removed in the next major version. User provided value will be ignored. */
|
|
81
|
-
batchSize?: number;
|
|
82
|
-
/** @deprecated Will be removed in the next major version. User provided value will be ignored. */
|
|
83
|
-
limit?: number;
|
|
84
|
-
/** @deprecated Will be removed in the next major version. User provided value will be ignored. */
|
|
85
|
-
noCursorTimeout?: boolean;
|
|
86
|
-
}
|
|
77
|
+
export type FindOneOptions = Omit<FindOptions, 'batchSize' | 'limit' | 'noCursorTimeout'>;
|
|
87
78
|
|
|
88
79
|
/** @internal */
|
|
89
80
|
export class FindOperation extends CommandOperation<CursorResponse> {
|
package/src/read_preference.ts
CHANGED
|
@@ -63,10 +63,6 @@ export class ReadPreference {
|
|
|
63
63
|
tags?: TagSet[];
|
|
64
64
|
hedge?: HedgeOptions;
|
|
65
65
|
maxStalenessSeconds?: number;
|
|
66
|
-
/**
|
|
67
|
-
* @deprecated This will be removed as dead code in the next major version.
|
|
68
|
-
*/
|
|
69
|
-
minWireVersion?: number;
|
|
70
66
|
|
|
71
67
|
public static PRIMARY = ReadPreferenceMode.primary;
|
|
72
68
|
public static PRIMARY_PREFERRED = ReadPreferenceMode.primaryPreferred;
|
|
@@ -100,7 +96,6 @@ export class ReadPreference {
|
|
|
100
96
|
this.tags = tags;
|
|
101
97
|
this.hedge = options?.hedge;
|
|
102
98
|
this.maxStalenessSeconds = undefined;
|
|
103
|
-
this.minWireVersion = undefined;
|
|
104
99
|
|
|
105
100
|
options = options ?? {};
|
|
106
101
|
if (options.maxStalenessSeconds != null) {
|
|
@@ -109,10 +104,6 @@ export class ReadPreference {
|
|
|
109
104
|
}
|
|
110
105
|
|
|
111
106
|
this.maxStalenessSeconds = options.maxStalenessSeconds;
|
|
112
|
-
|
|
113
|
-
// NOTE: The minimum required wire version is 5 for this read preference. If the existing
|
|
114
|
-
// topology has a lower value then a MongoError will be thrown during server selection.
|
|
115
|
-
this.minWireVersion = 5;
|
|
116
107
|
}
|
|
117
108
|
|
|
118
109
|
if (this.mode === ReadPreference.PRIMARY) {
|