mongodb 4.1.4 → 4.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -15
- package/lib/admin.js +3 -3
- package/lib/admin.js.map +1 -1
- package/lib/bson.js +16 -14
- package/lib/bson.js.map +1 -1
- package/lib/bulk/common.js +3 -4
- package/lib/bulk/common.js.map +1 -1
- package/lib/bulk/ordered.js +1 -1
- package/lib/bulk/ordered.js.map +1 -1
- package/lib/bulk/unordered.js +1 -1
- package/lib/bulk/unordered.js.map +1 -1
- package/lib/change_stream.js +6 -7
- package/lib/change_stream.js.map +1 -1
- package/lib/cmap/auth/auth_provider.js.map +1 -1
- package/lib/cmap/auth/gssapi.js +3 -3
- package/lib/cmap/auth/gssapi.js.map +1 -1
- package/lib/cmap/auth/mongo_credentials.js +16 -18
- package/lib/cmap/auth/mongo_credentials.js.map +1 -1
- package/lib/cmap/auth/mongocr.js +2 -2
- package/lib/cmap/auth/mongocr.js.map +1 -1
- package/lib/cmap/auth/mongodb_aws.js +6 -6
- package/lib/cmap/auth/mongodb_aws.js.map +1 -1
- package/lib/cmap/auth/plain.js +1 -1
- package/lib/cmap/auth/plain.js.map +1 -1
- package/lib/cmap/auth/providers.js +21 -0
- package/lib/cmap/auth/providers.js.map +1 -0
- package/lib/cmap/auth/scram.js +4 -4
- package/lib/cmap/auth/scram.js.map +1 -1
- package/lib/cmap/auth/x509.js +1 -1
- package/lib/cmap/auth/x509.js.map +1 -1
- package/lib/cmap/command_monitoring_events.js +1 -1
- package/lib/cmap/command_monitoring_events.js.map +1 -1
- package/lib/cmap/commands.js +20 -11
- package/lib/cmap/commands.js.map +1 -1
- package/lib/cmap/connect.js +102 -15
- package/lib/cmap/connect.js.map +1 -1
- package/lib/cmap/connection.js +27 -26
- package/lib/cmap/connection.js.map +1 -1
- package/lib/cmap/connection_pool.js +19 -30
- package/lib/cmap/connection_pool.js.map +1 -1
- package/lib/cmap/message_stream.js +3 -3
- package/lib/cmap/message_stream.js.map +1 -1
- package/lib/cmap/stream_description.js +4 -4
- package/lib/cmap/stream_description.js.map +1 -1
- package/lib/cmap/wire_protocol/compression.js.map +1 -1
- package/lib/cmap/wire_protocol/constants.js +4 -4
- package/lib/cmap/wire_protocol/shared.js +4 -3
- package/lib/cmap/wire_protocol/shared.js.map +1 -1
- package/lib/collection.js +46 -47
- package/lib/collection.js.map +1 -1
- package/lib/connection_string.js +106 -49
- package/lib/connection_string.js.map +1 -1
- package/lib/constants.js +108 -1
- package/lib/constants.js.map +1 -1
- package/lib/cursor/abstract_cursor.js +10 -7
- package/lib/cursor/abstract_cursor.js.map +1 -1
- package/lib/cursor/aggregation_cursor.js +1 -1
- package/lib/cursor/aggregation_cursor.js.map +1 -1
- package/lib/cursor/find_cursor.js +1 -1
- package/lib/cursor/find_cursor.js.map +1 -1
- package/lib/db.js +23 -13
- package/lib/db.js.map +1 -1
- package/lib/deps.js +0 -1
- package/lib/deps.js.map +1 -1
- package/lib/encrypter.js +12 -4
- package/lib/encrypter.js.map +1 -1
- package/lib/error.js +47 -24
- package/lib/error.js.map +1 -1
- package/lib/gridfs/download.js +1 -1
- package/lib/gridfs/download.js.map +1 -1
- package/lib/gridfs/index.js +3 -3
- package/lib/gridfs/index.js.map +1 -1
- package/lib/gridfs/upload.js +3 -2
- package/lib/gridfs/upload.js.map +1 -1
- package/lib/index.js +81 -81
- package/lib/index.js.map +1 -1
- package/lib/logger.js +1 -1
- package/lib/logger.js.map +1 -1
- package/lib/mongo_client.js +5 -5
- package/lib/mongo_client.js.map +1 -1
- package/lib/mongo_types.js.map +1 -1
- package/lib/operations/add_user.js +2 -2
- package/lib/operations/add_user.js.map +1 -1
- package/lib/operations/aggregate.js +2 -3
- package/lib/operations/aggregate.js.map +1 -1
- package/lib/operations/bulk_write.js.map +1 -1
- package/lib/operations/collections.js +1 -1
- package/lib/operations/collections.js.map +1 -1
- package/lib/operations/command.js +9 -6
- package/lib/operations/command.js.map +1 -1
- package/lib/operations/common_functions.js.map +1 -1
- package/lib/operations/connect.js +4 -13
- package/lib/operations/connect.js.map +1 -1
- package/lib/operations/count.js +1 -1
- package/lib/operations/count.js.map +1 -1
- package/lib/operations/count_documents.js.map +1 -1
- package/lib/operations/create_collection.js +3 -2
- package/lib/operations/create_collection.js.map +1 -1
- package/lib/operations/delete.js +3 -3
- package/lib/operations/delete.js.map +1 -1
- package/lib/operations/distinct.js +3 -3
- package/lib/operations/distinct.js.map +1 -1
- package/lib/operations/drop.js +1 -1
- package/lib/operations/drop.js.map +1 -1
- package/lib/operations/estimated_document_count.js +2 -2
- package/lib/operations/estimated_document_count.js.map +1 -1
- package/lib/operations/eval.js +2 -2
- package/lib/operations/eval.js.map +1 -1
- package/lib/operations/execute_operation.js +23 -7
- package/lib/operations/execute_operation.js.map +1 -1
- package/lib/operations/find.js +5 -5
- package/lib/operations/find.js.map +1 -1
- package/lib/operations/find_and_modify.js +2 -2
- package/lib/operations/find_and_modify.js.map +1 -1
- package/lib/operations/get_more.js +28 -0
- package/lib/operations/get_more.js.map +1 -0
- package/lib/operations/indexes.js +4 -4
- package/lib/operations/indexes.js.map +1 -1
- package/lib/operations/insert.js +3 -3
- package/lib/operations/insert.js.map +1 -1
- package/lib/operations/is_capped.js +1 -1
- package/lib/operations/is_capped.js.map +1 -1
- package/lib/operations/list_collections.js +11 -6
- package/lib/operations/list_collections.js.map +1 -1
- package/lib/operations/list_databases.js +1 -1
- package/lib/operations/list_databases.js.map +1 -1
- package/lib/operations/map_reduce.js +4 -3
- package/lib/operations/map_reduce.js.map +1 -1
- package/lib/operations/operation.js +4 -2
- package/lib/operations/operation.js.map +1 -1
- package/lib/operations/options_operation.js +1 -1
- package/lib/operations/options_operation.js.map +1 -1
- package/lib/operations/profiling_level.js +1 -1
- package/lib/operations/profiling_level.js.map +1 -1
- package/lib/operations/remove_user.js +1 -1
- package/lib/operations/remove_user.js.map +1 -1
- package/lib/operations/rename.js +3 -3
- package/lib/operations/rename.js.map +1 -1
- package/lib/operations/run_command.js +1 -1
- package/lib/operations/run_command.js.map +1 -1
- package/lib/operations/set_profiling_level.js +2 -2
- package/lib/operations/set_profiling_level.js.map +1 -1
- package/lib/operations/stats.js +1 -1
- package/lib/operations/stats.js.map +1 -1
- package/lib/operations/update.js +2 -2
- package/lib/operations/update.js.map +1 -1
- package/lib/operations/validate_collection.js +1 -1
- package/lib/operations/validate_collection.js.map +1 -1
- package/lib/read_preference.js +15 -5
- package/lib/read_preference.js.map +1 -1
- package/lib/sdam/monitor.js +4 -4
- package/lib/sdam/monitor.js.map +1 -1
- package/lib/sdam/server.js +31 -31
- package/lib/sdam/server.js.map +1 -1
- package/lib/sdam/server_description.js +1 -1
- package/lib/sdam/server_description.js.map +1 -1
- package/lib/sdam/server_selection.js +38 -3
- package/lib/sdam/server_selection.js.map +1 -1
- package/lib/sdam/srv_polling.js +11 -11
- package/lib/sdam/srv_polling.js.map +1 -1
- package/lib/sdam/topology.js +40 -62
- package/lib/sdam/topology.js.map +1 -1
- package/lib/sdam/topology_description.js +36 -14
- package/lib/sdam/topology_description.js.map +1 -1
- package/lib/sessions.js +13 -28
- package/lib/sessions.js.map +1 -1
- package/lib/transactions.js +1 -1
- package/lib/transactions.js.map +1 -1
- package/lib/utils.js +90 -23
- package/lib/utils.js.map +1 -1
- package/mongodb.d.ts +159 -65
- package/mongodb.ts34.d.ts +184 -65
- package/package.json +26 -24
- package/src/admin.ts +9 -9
- package/src/bson.ts +26 -17
- package/src/bulk/common.ts +26 -20
- package/src/bulk/ordered.ts +4 -4
- package/src/bulk/unordered.ts +5 -5
- package/src/change_stream.ts +35 -32
- package/src/cmap/auth/auth_provider.ts +3 -3
- package/src/cmap/auth/gssapi.ts +8 -8
- package/src/cmap/auth/mongo_credentials.ts +2 -6
- package/src/cmap/auth/mongocr.ts +3 -2
- package/src/cmap/auth/mongodb_aws.ts +10 -11
- package/src/cmap/auth/plain.ts +1 -1
- package/src/cmap/auth/providers.ts +21 -0
- package/src/cmap/auth/scram.ts +9 -9
- package/src/cmap/auth/x509.ts +3 -3
- package/src/cmap/command_monitoring_events.ts +2 -2
- package/src/cmap/commands.ts +30 -19
- package/src/cmap/connect.ts +142 -22
- package/src/cmap/connection.ts +73 -52
- package/src/cmap/connection_pool.ts +39 -39
- package/src/cmap/connection_pool_events.ts +1 -1
- package/src/cmap/message_stream.ts +9 -8
- package/src/cmap/stream_description.ts +5 -5
- package/src/cmap/wire_protocol/compression.ts +2 -2
- package/src/cmap/wire_protocol/constants.ts +4 -4
- package/src/cmap/wire_protocol/shared.ts +10 -9
- package/src/collection.ts +133 -106
- package/src/connection_string.ts +141 -60
- package/src/constants.ts +116 -0
- package/src/cursor/abstract_cursor.ts +21 -22
- package/src/cursor/aggregation_cursor.ts +6 -6
- package/src/cursor/find_cursor.ts +2 -2
- package/src/db.ts +49 -39
- package/src/deps.ts +3 -1
- package/src/encrypter.ts +12 -3
- package/src/error.ts +52 -24
- package/src/gridfs/download.ts +10 -8
- package/src/gridfs/index.ts +11 -11
- package/src/gridfs/upload.ts +13 -10
- package/src/index.ts +204 -199
- package/src/logger.ts +2 -1
- package/src/mongo_client.ts +58 -32
- package/src/mongo_types.ts +98 -20
- package/src/operations/add_user.ts +6 -5
- package/src/operations/aggregate.ts +6 -7
- package/src/operations/bulk_write.ts +5 -5
- package/src/operations/collections.ts +2 -2
- package/src/operations/command.ts +19 -8
- package/src/operations/common_functions.ts +4 -4
- package/src/operations/connect.ts +4 -14
- package/src/operations/count.ts +4 -4
- package/src/operations/count_documents.ts +3 -3
- package/src/operations/create_collection.ts +8 -7
- package/src/operations/delete.ts +5 -5
- package/src/operations/distinct.ts +4 -4
- package/src/operations/drop.ts +4 -4
- package/src/operations/estimated_document_count.ts +5 -5
- package/src/operations/eval.ts +5 -5
- package/src/operations/execute_operation.ts +30 -11
- package/src/operations/find.ts +14 -14
- package/src/operations/find_and_modify.ts +7 -7
- package/src/operations/get_more.ts +49 -0
- package/src/operations/indexes.ts +16 -16
- package/src/operations/insert.ts +9 -9
- package/src/operations/is_capped.ts +3 -3
- package/src/operations/list_collections.ts +18 -10
- package/src/operations/list_databases.ts +4 -4
- package/src/operations/map_reduce.ts +10 -9
- package/src/operations/operation.ts +8 -4
- package/src/operations/options_operation.ts +3 -3
- package/src/operations/profiling_level.ts +4 -4
- package/src/operations/remove_user.ts +4 -4
- package/src/operations/rename.ts +6 -6
- package/src/operations/run_command.ts +3 -3
- package/src/operations/set_profiling_level.ts +6 -5
- package/src/operations/stats.ts +4 -4
- package/src/operations/update.ts +10 -10
- package/src/operations/validate_collection.ts +4 -4
- package/src/read_preference.ts +18 -7
- package/src/sdam/common.ts +2 -2
- package/src/sdam/events.ts +1 -1
- package/src/sdam/monitor.ts +13 -14
- package/src/sdam/server.ts +71 -61
- package/src/sdam/server_description.ts +4 -4
- package/src/sdam/server_selection.ts +46 -3
- package/src/sdam/srv_polling.ts +15 -13
- package/src/sdam/topology.ts +89 -90
- package/src/sdam/topology_description.ts +39 -15
- package/src/sessions.ts +31 -48
- package/src/transactions.ts +6 -6
- package/src/utils.ts +123 -43
- package/lib/cmap/auth/defaultAuthProviders.js +0 -30
- package/lib/cmap/auth/defaultAuthProviders.js.map +0 -1
- package/src/cmap/auth/defaultAuthProviders.ts +0 -32
package/src/connection_string.ts
CHANGED
|
@@ -2,22 +2,14 @@ import * as dns from 'dns';
|
|
|
2
2
|
import * as fs from 'fs';
|
|
3
3
|
import ConnectionString from 'mongodb-connection-string-url';
|
|
4
4
|
import { URLSearchParams } from 'url';
|
|
5
|
-
|
|
6
|
-
import { ReadPreference, ReadPreferenceMode } from './read_preference';
|
|
7
|
-
import { ReadConcern, ReadConcernLevel } from './read_concern';
|
|
8
|
-
import { W, WriteConcern } from './write_concern';
|
|
9
|
-
import { MongoAPIError, MongoInvalidArgumentError, MongoParseError } from './error';
|
|
10
|
-
import {
|
|
11
|
-
AnyOptions,
|
|
12
|
-
Callback,
|
|
13
|
-
DEFAULT_PK_FACTORY,
|
|
14
|
-
isRecord,
|
|
15
|
-
makeClientMetadata,
|
|
16
|
-
setDifference,
|
|
17
|
-
HostAddress,
|
|
18
|
-
emitWarning
|
|
19
|
-
} from './utils';
|
|
5
|
+
|
|
20
6
|
import type { Document } from './bson';
|
|
7
|
+
import { MongoCredentials } from './cmap/auth/mongo_credentials';
|
|
8
|
+
import { AUTH_MECHS_AUTH_SRC_EXTERNAL, AuthMechanism } from './cmap/auth/providers';
|
|
9
|
+
import { Compressor, CompressorName } from './cmap/wire_protocol/compression';
|
|
10
|
+
import { Encrypter } from './encrypter';
|
|
11
|
+
import { MongoAPIError, MongoInvalidArgumentError, MongoParseError } from './error';
|
|
12
|
+
import { Logger, LoggerLevel } from './logger';
|
|
21
13
|
import {
|
|
22
14
|
DriverInfo,
|
|
23
15
|
MongoClient,
|
|
@@ -27,12 +19,21 @@ import {
|
|
|
27
19
|
ServerApi,
|
|
28
20
|
ServerApiVersion
|
|
29
21
|
} from './mongo_client';
|
|
30
|
-
import { MongoCredentials } from './cmap/auth/mongo_credentials';
|
|
31
|
-
import type { TagSet } from './sdam/server_description';
|
|
32
|
-
import { Logger, LoggerLevel } from './logger';
|
|
33
22
|
import { PromiseProvider } from './promise_provider';
|
|
34
|
-
import {
|
|
35
|
-
import {
|
|
23
|
+
import { ReadConcern, ReadConcernLevel } from './read_concern';
|
|
24
|
+
import { ReadPreference, ReadPreferenceMode } from './read_preference';
|
|
25
|
+
import type { TagSet } from './sdam/server_description';
|
|
26
|
+
import {
|
|
27
|
+
AnyOptions,
|
|
28
|
+
Callback,
|
|
29
|
+
DEFAULT_PK_FACTORY,
|
|
30
|
+
emitWarning,
|
|
31
|
+
HostAddress,
|
|
32
|
+
isRecord,
|
|
33
|
+
makeClientMetadata,
|
|
34
|
+
setDifference
|
|
35
|
+
} from './utils';
|
|
36
|
+
import { W, WriteConcern } from './write_concern';
|
|
36
37
|
|
|
37
38
|
const VALID_TXT_RECORDS = ['authSource', 'replicaSet', 'loadBalanced'];
|
|
38
39
|
|
|
@@ -75,7 +76,7 @@ export function resolveSRVRecord(options: MongoOptions, callback: Callback<HostA
|
|
|
75
76
|
|
|
76
77
|
// Resolve the SRV record and use the result as the list of hosts to connect to.
|
|
77
78
|
const lookupAddress = options.srvHost;
|
|
78
|
-
dns.resolveSrv(`
|
|
79
|
+
dns.resolveSrv(`_${options.srvServiceName}._tcp.${lookupAddress}`, (err, addresses) => {
|
|
79
80
|
if (err) return callback(err);
|
|
80
81
|
|
|
81
82
|
if (addresses.length === 0) {
|
|
@@ -92,7 +93,7 @@ export function resolveSRVRecord(options: MongoOptions, callback: Callback<HostA
|
|
|
92
93
|
HostAddress.fromString(`${r.name}:${r.port ?? 27017}`)
|
|
93
94
|
);
|
|
94
95
|
|
|
95
|
-
const lbError = validateLoadBalancedOptions(hostAddresses, options);
|
|
96
|
+
const lbError = validateLoadBalancedOptions(hostAddresses, options, true);
|
|
96
97
|
if (lbError) {
|
|
97
98
|
return callback(lbError);
|
|
98
99
|
}
|
|
@@ -116,15 +117,20 @@ export function resolveSRVRecord(options: MongoOptions, callback: Callback<HostA
|
|
|
116
117
|
);
|
|
117
118
|
}
|
|
118
119
|
|
|
120
|
+
if (VALID_TXT_RECORDS.some(option => txtRecordOptions.get(option) === '')) {
|
|
121
|
+
return callback(new MongoParseError('Cannot have empty URI params in DNS TXT Record'));
|
|
122
|
+
}
|
|
123
|
+
|
|
119
124
|
const source = txtRecordOptions.get('authSource') ?? undefined;
|
|
120
125
|
const replicaSet = txtRecordOptions.get('replicaSet') ?? undefined;
|
|
121
126
|
const loadBalanced = txtRecordOptions.get('loadBalanced') ?? undefined;
|
|
122
127
|
|
|
123
|
-
if (
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
+
if (
|
|
129
|
+
!options.userSpecifiedAuthSource &&
|
|
130
|
+
source &&
|
|
131
|
+
options.credentials &&
|
|
132
|
+
!AUTH_MECHS_AUTH_SRC_EXTERNAL.has(options.credentials.mechanism)
|
|
133
|
+
) {
|
|
128
134
|
options.credentials = MongoCredentials.merge(options.credentials, { source });
|
|
129
135
|
}
|
|
130
136
|
|
|
@@ -136,7 +142,11 @@ export function resolveSRVRecord(options: MongoOptions, callback: Callback<HostA
|
|
|
136
142
|
options.loadBalanced = true;
|
|
137
143
|
}
|
|
138
144
|
|
|
139
|
-
|
|
145
|
+
if (options.replicaSet && options.srvMaxHosts > 0) {
|
|
146
|
+
return callback(new MongoParseError('Cannot combine replicaSet option with srvMaxHosts'));
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const lbError = validateLoadBalancedOptions(hostAddresses, options, true);
|
|
140
150
|
if (lbError) {
|
|
141
151
|
return callback(lbError);
|
|
142
152
|
}
|
|
@@ -251,13 +261,6 @@ export function parseOptions(
|
|
|
251
261
|
|
|
252
262
|
const mongoOptions = Object.create(null);
|
|
253
263
|
mongoOptions.hosts = isSRV ? [] : hosts.map(HostAddress.fromString);
|
|
254
|
-
if (isSRV) {
|
|
255
|
-
// SRV Record is resolved upon connecting
|
|
256
|
-
mongoOptions.srvHost = hosts[0];
|
|
257
|
-
if (!url.searchParams.has('tls') && !url.searchParams.has('ssl')) {
|
|
258
|
-
options.tls = true;
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
264
|
|
|
262
265
|
const urlOptions = new CaseInsensitiveMap();
|
|
263
266
|
|
|
@@ -289,17 +292,6 @@ export function parseOptions(
|
|
|
289
292
|
throw new MongoAPIError('URI cannot contain options with no value');
|
|
290
293
|
}
|
|
291
294
|
|
|
292
|
-
if (key.toLowerCase() === 'serverapi') {
|
|
293
|
-
throw new MongoParseError(
|
|
294
|
-
'URI cannot contain `serverApi`, it can only be passed to the client'
|
|
295
|
-
);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
if (key.toLowerCase() === 'authsource' && urlOptions.has('authSource')) {
|
|
299
|
-
// If authSource is an explicit key in the urlOptions we need to remove the implicit dbName
|
|
300
|
-
urlOptions.delete('authSource');
|
|
301
|
-
}
|
|
302
|
-
|
|
303
295
|
if (!urlOptions.has(key)) {
|
|
304
296
|
urlOptions.set(key, values);
|
|
305
297
|
}
|
|
@@ -309,10 +301,20 @@ export function parseOptions(
|
|
|
309
301
|
Object.entries(options).filter(([, v]) => v != null)
|
|
310
302
|
);
|
|
311
303
|
|
|
304
|
+
// Validate options that can only be provided by one of uri or object
|
|
305
|
+
|
|
306
|
+
if (urlOptions.has('serverApi')) {
|
|
307
|
+
throw new MongoParseError(
|
|
308
|
+
'URI cannot contain `serverApi`, it can only be passed to the client'
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
312
|
if (objectOptions.has('loadBalanced')) {
|
|
313
313
|
throw new MongoParseError('loadBalanced is only a valid option in the URI');
|
|
314
314
|
}
|
|
315
315
|
|
|
316
|
+
// All option collection
|
|
317
|
+
|
|
316
318
|
const allOptions = new CaseInsensitiveMap();
|
|
317
319
|
|
|
318
320
|
const allKeys = new Set<string>([
|
|
@@ -360,6 +362,8 @@ export function parseOptions(
|
|
|
360
362
|
);
|
|
361
363
|
}
|
|
362
364
|
|
|
365
|
+
// Option parsing and setting
|
|
366
|
+
|
|
363
367
|
for (const [key, descriptor] of Object.entries(OPTIONS)) {
|
|
364
368
|
const values = allOptions.get(key);
|
|
365
369
|
if (!values || values.length === 0) continue;
|
|
@@ -401,25 +405,78 @@ export function parseOptions(
|
|
|
401
405
|
|
|
402
406
|
if (options.promiseLibrary) PromiseProvider.set(options.promiseLibrary);
|
|
403
407
|
|
|
404
|
-
|
|
405
|
-
throw new MongoAPIError('SRV URI does not support directConnection');
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
const lbError = validateLoadBalancedOptions(hosts, mongoOptions);
|
|
408
|
+
const lbError = validateLoadBalancedOptions(hosts, mongoOptions, isSRV);
|
|
409
409
|
if (lbError) {
|
|
410
410
|
throw lbError;
|
|
411
411
|
}
|
|
412
|
+
if (mongoClient && mongoOptions.autoEncryption) {
|
|
413
|
+
Encrypter.checkForMongoCrypt();
|
|
414
|
+
mongoOptions.encrypter = new Encrypter(mongoClient, uri, options);
|
|
415
|
+
mongoOptions.autoEncrypter = mongoOptions.encrypter.autoEncrypter;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
// Potential SRV Overrides and SRV connection string validations
|
|
412
419
|
|
|
413
|
-
// Potential SRV Overrides
|
|
414
420
|
mongoOptions.userSpecifiedAuthSource =
|
|
415
421
|
objectOptions.has('authSource') || urlOptions.has('authSource');
|
|
416
422
|
mongoOptions.userSpecifiedReplicaSet =
|
|
417
423
|
objectOptions.has('replicaSet') || urlOptions.has('replicaSet');
|
|
418
424
|
|
|
419
|
-
if (
|
|
420
|
-
|
|
421
|
-
mongoOptions.
|
|
422
|
-
|
|
425
|
+
if (isSRV) {
|
|
426
|
+
// SRV Record is resolved upon connecting
|
|
427
|
+
mongoOptions.srvHost = hosts[0];
|
|
428
|
+
|
|
429
|
+
if (mongoOptions.directConnection) {
|
|
430
|
+
throw new MongoAPIError('SRV URI does not support directConnection');
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
if (mongoOptions.srvMaxHosts > 0 && typeof mongoOptions.replicaSet === 'string') {
|
|
434
|
+
throw new MongoParseError('Cannot use srvMaxHosts option with replicaSet');
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
// SRV turns on TLS by default, but users can override and turn it off
|
|
438
|
+
const noUserSpecifiedTLS = !objectOptions.has('tls') && !urlOptions.has('tls');
|
|
439
|
+
const noUserSpecifiedSSL = !objectOptions.has('ssl') && !urlOptions.has('ssl');
|
|
440
|
+
if (noUserSpecifiedTLS && noUserSpecifiedSSL) {
|
|
441
|
+
mongoOptions.tls = true;
|
|
442
|
+
}
|
|
443
|
+
} else {
|
|
444
|
+
const userSpecifiedSrvOptions =
|
|
445
|
+
urlOptions.has('srvMaxHosts') ||
|
|
446
|
+
objectOptions.has('srvMaxHosts') ||
|
|
447
|
+
urlOptions.has('srvServiceName') ||
|
|
448
|
+
objectOptions.has('srvServiceName');
|
|
449
|
+
|
|
450
|
+
if (userSpecifiedSrvOptions) {
|
|
451
|
+
throw new MongoParseError(
|
|
452
|
+
'Cannot use srvMaxHosts or srvServiceName with a non-srv connection string'
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
if (
|
|
458
|
+
!mongoOptions.proxyHost &&
|
|
459
|
+
(mongoOptions.proxyPort || mongoOptions.proxyUsername || mongoOptions.proxyPassword)
|
|
460
|
+
) {
|
|
461
|
+
throw new MongoParseError('Must specify proxyHost if other proxy options are passed');
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
if (
|
|
465
|
+
(mongoOptions.proxyUsername && !mongoOptions.proxyPassword) ||
|
|
466
|
+
(!mongoOptions.proxyUsername && mongoOptions.proxyPassword)
|
|
467
|
+
) {
|
|
468
|
+
throw new MongoParseError('Can only specify both of proxy username/password or neither');
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
if (
|
|
472
|
+
urlOptions.get('proxyHost')?.length > 1 ||
|
|
473
|
+
urlOptions.get('proxyPort')?.length > 1 ||
|
|
474
|
+
urlOptions.get('proxyUsername')?.length > 1 ||
|
|
475
|
+
urlOptions.get('proxyPassword')?.length > 1
|
|
476
|
+
) {
|
|
477
|
+
throw new MongoParseError(
|
|
478
|
+
'Proxy options cannot be specified multiple times in the connection string'
|
|
479
|
+
);
|
|
423
480
|
}
|
|
424
481
|
|
|
425
482
|
return mongoOptions;
|
|
@@ -427,7 +484,8 @@ export function parseOptions(
|
|
|
427
484
|
|
|
428
485
|
function validateLoadBalancedOptions(
|
|
429
486
|
hosts: HostAddress[] | string[],
|
|
430
|
-
mongoOptions: MongoOptions
|
|
487
|
+
mongoOptions: MongoOptions,
|
|
488
|
+
isSrv: boolean
|
|
431
489
|
): MongoParseError | undefined {
|
|
432
490
|
if (mongoOptions.loadBalanced) {
|
|
433
491
|
if (hosts.length > 1) {
|
|
@@ -439,6 +497,10 @@ function validateLoadBalancedOptions(
|
|
|
439
497
|
if (mongoOptions.directConnection) {
|
|
440
498
|
return new MongoParseError(LB_DIRECT_CONNECTION_ERROR);
|
|
441
499
|
}
|
|
500
|
+
|
|
501
|
+
if (isSrv && mongoOptions.srvMaxHosts > 0) {
|
|
502
|
+
return new MongoParseError('Cannot limit srv hosts with loadBalanced enabled');
|
|
503
|
+
}
|
|
442
504
|
}
|
|
443
505
|
}
|
|
444
506
|
|
|
@@ -538,9 +600,7 @@ export const OPTIONS = {
|
|
|
538
600
|
let source = options.credentials?.source;
|
|
539
601
|
if (
|
|
540
602
|
mechanism === AuthMechanism.MONGODB_PLAIN ||
|
|
541
|
-
mechanism
|
|
542
|
-
mechanism === AuthMechanism.MONGODB_AWS ||
|
|
543
|
-
mechanism === AuthMechanism.MONGODB_X509
|
|
603
|
+
AUTH_MECHS_AUTH_SRC_EXTERNAL.has(mechanism)
|
|
544
604
|
) {
|
|
545
605
|
// some mechanisms have '$external' as the Auth Source
|
|
546
606
|
source = '$external';
|
|
@@ -657,6 +717,7 @@ export const OPTIONS = {
|
|
|
657
717
|
});
|
|
658
718
|
}
|
|
659
719
|
},
|
|
720
|
+
enableUtf8Validation: { type: 'boolean', default: true },
|
|
660
721
|
family: {
|
|
661
722
|
transform({ name, values: [value] }): 4 | 6 {
|
|
662
723
|
const transformValue = getInt(name, value);
|
|
@@ -824,6 +885,18 @@ export const OPTIONS = {
|
|
|
824
885
|
promoteValues: {
|
|
825
886
|
type: 'boolean'
|
|
826
887
|
},
|
|
888
|
+
proxyHost: {
|
|
889
|
+
type: 'string'
|
|
890
|
+
},
|
|
891
|
+
proxyPassword: {
|
|
892
|
+
type: 'string'
|
|
893
|
+
},
|
|
894
|
+
proxyPort: {
|
|
895
|
+
type: 'uint'
|
|
896
|
+
},
|
|
897
|
+
proxyUsername: {
|
|
898
|
+
type: 'string'
|
|
899
|
+
},
|
|
827
900
|
raw: {
|
|
828
901
|
default: false,
|
|
829
902
|
type: 'boolean'
|
|
@@ -924,6 +997,14 @@ export const OPTIONS = {
|
|
|
924
997
|
default: 0,
|
|
925
998
|
type: 'uint'
|
|
926
999
|
},
|
|
1000
|
+
srvMaxHosts: {
|
|
1001
|
+
type: 'uint',
|
|
1002
|
+
default: 0
|
|
1003
|
+
},
|
|
1004
|
+
srvServiceName: {
|
|
1005
|
+
type: 'string',
|
|
1006
|
+
default: 'mongodb'
|
|
1007
|
+
},
|
|
927
1008
|
ssl: {
|
|
928
1009
|
target: 'tls',
|
|
929
1010
|
type: 'boolean'
|
package/src/constants.ts
CHANGED
|
@@ -4,3 +4,119 @@ export const SYSTEM_PROFILE_COLLECTION = 'system.profile';
|
|
|
4
4
|
export const SYSTEM_USER_COLLECTION = 'system.users';
|
|
5
5
|
export const SYSTEM_COMMAND_COLLECTION = '$cmd';
|
|
6
6
|
export const SYSTEM_JS_COLLECTION = 'system.js';
|
|
7
|
+
|
|
8
|
+
// events
|
|
9
|
+
export const ERROR = 'error' as const;
|
|
10
|
+
export const TIMEOUT = 'timeout' as const;
|
|
11
|
+
export const CLOSE = 'close' as const;
|
|
12
|
+
export const OPEN = 'open' as const;
|
|
13
|
+
export const CONNECT = 'connect' as const;
|
|
14
|
+
export const CLOSED = 'closed' as const;
|
|
15
|
+
export const ENDED = 'ended' as const;
|
|
16
|
+
export const MESSAGE = 'message' as const;
|
|
17
|
+
export const PINNED = 'pinned' as const;
|
|
18
|
+
export const UNPINNED = 'unpinned' as const;
|
|
19
|
+
export const DESCRIPTION_RECEIVED = 'descriptionReceived';
|
|
20
|
+
export const SERVER_OPENING = 'serverOpening' as const;
|
|
21
|
+
export const SERVER_CLOSED = 'serverClosed' as const;
|
|
22
|
+
export const SERVER_DESCRIPTION_CHANGED = 'serverDescriptionChanged' as const;
|
|
23
|
+
export const TOPOLOGY_OPENING = 'topologyOpening' as const;
|
|
24
|
+
export const TOPOLOGY_CLOSED = 'topologyClosed' as const;
|
|
25
|
+
export const TOPOLOGY_DESCRIPTION_CHANGED = 'topologyDescriptionChanged' as const;
|
|
26
|
+
export const CONNECTION_POOL_CREATED = 'connectionPoolCreated' as const;
|
|
27
|
+
export const CONNECTION_POOL_CLOSED = 'connectionPoolClosed' as const;
|
|
28
|
+
export const CONNECTION_POOL_CLEARED = 'connectionPoolCleared' as const;
|
|
29
|
+
export const CONNECTION_CREATED = 'connectionCreated' as const;
|
|
30
|
+
export const CONNECTION_READY = 'connectionReady' as const;
|
|
31
|
+
export const CONNECTION_CLOSED = 'connectionClosed' as const;
|
|
32
|
+
export const CONNECTION_CHECK_OUT_STARTED = 'connectionCheckOutStarted' as const;
|
|
33
|
+
export const CONNECTION_CHECK_OUT_FAILED = 'connectionCheckOutFailed' as const;
|
|
34
|
+
export const CONNECTION_CHECKED_OUT = 'connectionCheckedOut' as const;
|
|
35
|
+
export const CONNECTION_CHECKED_IN = 'connectionCheckedIn' as const;
|
|
36
|
+
export const CLUSTER_TIME_RECEIVED = 'clusterTimeReceived' as const;
|
|
37
|
+
export const COMMAND_STARTED = 'commandStarted' as const;
|
|
38
|
+
export const COMMAND_SUCCEEDED = 'commandSucceeded' as const;
|
|
39
|
+
export const COMMAND_FAILED = 'commandFailed' as const;
|
|
40
|
+
export const SERVER_HEARTBEAT_STARTED = 'serverHeartbeatStarted' as const;
|
|
41
|
+
export const SERVER_HEARTBEAT_SUCCEEDED = 'serverHeartbeatSucceeded' as const;
|
|
42
|
+
export const SERVER_HEARTBEAT_FAILED = 'serverHeartbeatFailed' as const;
|
|
43
|
+
|
|
44
|
+
/** @public */
|
|
45
|
+
export const HEARTBEAT_EVENTS = Object.freeze([
|
|
46
|
+
SERVER_HEARTBEAT_STARTED,
|
|
47
|
+
SERVER_HEARTBEAT_SUCCEEDED,
|
|
48
|
+
SERVER_HEARTBEAT_FAILED
|
|
49
|
+
] as const);
|
|
50
|
+
|
|
51
|
+
/** @public */
|
|
52
|
+
export const CMAP_EVENTS = Object.freeze([
|
|
53
|
+
CONNECTION_POOL_CREATED,
|
|
54
|
+
CONNECTION_POOL_CLOSED,
|
|
55
|
+
CONNECTION_CREATED,
|
|
56
|
+
CONNECTION_READY,
|
|
57
|
+
CONNECTION_CLOSED,
|
|
58
|
+
CONNECTION_CHECK_OUT_STARTED,
|
|
59
|
+
CONNECTION_CHECK_OUT_FAILED,
|
|
60
|
+
CONNECTION_CHECKED_OUT,
|
|
61
|
+
CONNECTION_CHECKED_IN,
|
|
62
|
+
CONNECTION_POOL_CLEARED
|
|
63
|
+
] as const);
|
|
64
|
+
|
|
65
|
+
/** @public */
|
|
66
|
+
export const TOPOLOGY_EVENTS = Object.freeze([
|
|
67
|
+
SERVER_OPENING,
|
|
68
|
+
SERVER_CLOSED,
|
|
69
|
+
SERVER_DESCRIPTION_CHANGED,
|
|
70
|
+
TOPOLOGY_OPENING,
|
|
71
|
+
TOPOLOGY_CLOSED,
|
|
72
|
+
TOPOLOGY_DESCRIPTION_CHANGED,
|
|
73
|
+
ERROR,
|
|
74
|
+
TIMEOUT,
|
|
75
|
+
CLOSE
|
|
76
|
+
] as const);
|
|
77
|
+
|
|
78
|
+
/** @public */
|
|
79
|
+
export const APM_EVENTS = Object.freeze([
|
|
80
|
+
COMMAND_STARTED,
|
|
81
|
+
COMMAND_SUCCEEDED,
|
|
82
|
+
COMMAND_FAILED
|
|
83
|
+
] as const);
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* All events that we relay to the `Topology`
|
|
87
|
+
* @internal
|
|
88
|
+
*/
|
|
89
|
+
export const SERVER_RELAY_EVENTS = Object.freeze([
|
|
90
|
+
SERVER_HEARTBEAT_STARTED,
|
|
91
|
+
SERVER_HEARTBEAT_SUCCEEDED,
|
|
92
|
+
SERVER_HEARTBEAT_FAILED,
|
|
93
|
+
COMMAND_STARTED,
|
|
94
|
+
COMMAND_SUCCEEDED,
|
|
95
|
+
COMMAND_FAILED,
|
|
96
|
+
...CMAP_EVENTS
|
|
97
|
+
] as const);
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* All events we listen to from `Server` instances, but do not forward to the client
|
|
101
|
+
* @internal
|
|
102
|
+
*/
|
|
103
|
+
export const LOCAL_SERVER_EVENTS = Object.freeze([
|
|
104
|
+
CONNECT,
|
|
105
|
+
DESCRIPTION_RECEIVED,
|
|
106
|
+
CLOSED,
|
|
107
|
+
ENDED
|
|
108
|
+
] as const);
|
|
109
|
+
|
|
110
|
+
/** @public */
|
|
111
|
+
export const MONGO_CLIENT_EVENTS = Object.freeze([
|
|
112
|
+
...CMAP_EVENTS,
|
|
113
|
+
...APM_EVENTS,
|
|
114
|
+
...TOPOLOGY_EVENTS,
|
|
115
|
+
...HEARTBEAT_EVENTS
|
|
116
|
+
] as const);
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* @internal
|
|
120
|
+
* The legacy hello command that was deprecated in MongoDB 5.0.
|
|
121
|
+
*/
|
|
122
|
+
export const LEGACY_HELLO_COMMAND = 'ismaster';
|
|
@@ -1,22 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import {
|
|
1
|
+
import { Readable, Transform } from 'stream';
|
|
2
|
+
|
|
3
|
+
import { BSONSerializeOptions, Document, Long, pluckBSONSerializeOptions } from '../bson';
|
|
4
4
|
import {
|
|
5
5
|
AnyError,
|
|
6
|
-
MongoRuntimeError,
|
|
7
|
-
MongoNetworkError,
|
|
8
|
-
MongoInvalidArgumentError,
|
|
9
6
|
MongoCursorExhaustedError,
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
MongoCursorInUseError,
|
|
8
|
+
MongoInvalidArgumentError,
|
|
9
|
+
MongoNetworkError,
|
|
10
|
+
MongoRuntimeError,
|
|
11
|
+
MongoTailableCursorError
|
|
12
12
|
} from '../error';
|
|
13
|
+
import { TODO_NODE_3286, TypedEventEmitter } from '../mongo_types';
|
|
14
|
+
import { executeOperation, ExecutionResult } from '../operations/execute_operation';
|
|
15
|
+
import { GetMoreOperation } from '../operations/get_more';
|
|
16
|
+
import { ReadConcern, ReadConcernLike } from '../read_concern';
|
|
13
17
|
import { ReadPreference, ReadPreferenceLike } from '../read_preference';
|
|
14
18
|
import type { Server } from '../sdam/server';
|
|
15
19
|
import type { Topology } from '../sdam/topology';
|
|
16
|
-
import {
|
|
17
|
-
import
|
|
18
|
-
import { ReadConcern, ReadConcernLike } from '../read_concern';
|
|
19
|
-
import { TODO_NODE_3286, TypedEventEmitter } from '../mongo_types';
|
|
20
|
+
import { ClientSession, maybeClearPinnedConnection } from '../sessions';
|
|
21
|
+
import { Callback, maybePromise, MongoDBNamespace, ns } from '../utils';
|
|
20
22
|
|
|
21
23
|
/** @internal */
|
|
22
24
|
const kId = Symbol('id');
|
|
@@ -610,16 +612,13 @@ export abstract class AbstractCursor<
|
|
|
610
612
|
return;
|
|
611
613
|
}
|
|
612
614
|
|
|
613
|
-
server
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
},
|
|
621
|
-
callback
|
|
622
|
-
);
|
|
615
|
+
const getMoreOperation = new GetMoreOperation(cursorNs, cursorId, server, {
|
|
616
|
+
...this[kOptions],
|
|
617
|
+
session: this[kSession],
|
|
618
|
+
batchSize
|
|
619
|
+
});
|
|
620
|
+
|
|
621
|
+
executeOperation(this.topology, getMoreOperation, callback);
|
|
623
622
|
}
|
|
624
623
|
}
|
|
625
624
|
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
import type { Document } from '../bson';
|
|
2
|
+
import type { ExplainVerbosityLike } from '../explain';
|
|
1
3
|
import { AggregateOperation, AggregateOptions } from '../operations/aggregate';
|
|
2
|
-
import { AbstractCursor, assertUninitialized } from './abstract_cursor';
|
|
3
4
|
import { executeOperation, ExecutionResult } from '../operations/execute_operation';
|
|
4
|
-
import { mergeOptions } from '../utils';
|
|
5
|
-
import type { Document } from '../bson';
|
|
6
|
-
import type { Sort } from '../sort';
|
|
7
5
|
import type { Topology } from '../sdam/topology';
|
|
8
|
-
import type { Callback, MongoDBNamespace } from '../utils';
|
|
9
6
|
import type { ClientSession } from '../sessions';
|
|
7
|
+
import type { Sort } from '../sort';
|
|
8
|
+
import type { Callback, MongoDBNamespace } from '../utils';
|
|
9
|
+
import { mergeOptions } from '../utils';
|
|
10
10
|
import type { AbstractCursorOptions } from './abstract_cursor';
|
|
11
|
-
import
|
|
11
|
+
import { AbstractCursor, assertUninitialized } from './abstract_cursor';
|
|
12
12
|
|
|
13
13
|
/** @public */
|
|
14
14
|
export interface AggregationCursorOptions extends AbstractCursorOptions, AggregateOptions {}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import type { Document } from '../bson';
|
|
2
2
|
import { MongoInvalidArgumentError, MongoTailableCursorError } from '../error';
|
|
3
3
|
import type { ExplainVerbosityLike } from '../explain';
|
|
4
|
+
import type { CollationOptions } from '../operations/command';
|
|
4
5
|
import { CountOperation, CountOptions } from '../operations/count';
|
|
5
6
|
import { executeOperation, ExecutionResult } from '../operations/execute_operation';
|
|
6
7
|
import { FindOperation, FindOptions } from '../operations/find';
|
|
7
|
-
import { mergeOptions } from '../utils';
|
|
8
8
|
import type { Hint } from '../operations/operation';
|
|
9
|
-
import type { CollationOptions } from '../operations/command';
|
|
10
9
|
import type { Topology } from '../sdam/topology';
|
|
11
10
|
import type { ClientSession } from '../sessions';
|
|
12
11
|
import { formatSort, Sort, SortDirection } from '../sort';
|
|
13
12
|
import type { Callback, MongoDBNamespace } from '../utils';
|
|
13
|
+
import { mergeOptions } from '../utils';
|
|
14
14
|
import { AbstractCursor, assertUninitialized } from './abstract_cursor';
|
|
15
15
|
|
|
16
16
|
/** @internal */
|