mongodb 4.0.0 → 4.1.2
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 +62 -30
- package/lib/bson.js +1 -0
- package/lib/bson.js.map +1 -1
- package/lib/bulk/common.js +53 -30
- package/lib/bulk/common.js.map +1 -1
- package/lib/bulk/ordered.js +3 -2
- package/lib/bulk/ordered.js.map +1 -1
- package/lib/bulk/unordered.js +3 -2
- package/lib/bulk/unordered.js.map +1 -1
- package/lib/change_stream.js +23 -13
- package/lib/change_stream.js.map +1 -1
- package/lib/cmap/auth/auth_provider.js +2 -1
- package/lib/cmap/auth/auth_provider.js.map +1 -1
- package/lib/cmap/auth/gssapi.js +5 -4
- package/lib/cmap/auth/gssapi.js.map +1 -1
- package/lib/cmap/auth/mongo_credentials.js +9 -5
- 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 +32 -32
- 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/scram.js +15 -12
- package/lib/cmap/auth/scram.js.map +1 -1
- package/lib/cmap/auth/x509.js +2 -2
- package/lib/cmap/auth/x509.js.map +1 -1
- package/lib/cmap/command_monitoring_events.js +26 -10
- package/lib/cmap/command_monitoring_events.js.map +1 -1
- package/lib/cmap/commands.js +9 -5
- package/lib/cmap/commands.js.map +1 -1
- package/lib/cmap/connect.js +23 -9
- package/lib/cmap/connect.js.map +1 -1
- package/lib/cmap/connection.js +43 -46
- package/lib/cmap/connection.js.map +1 -1
- package/lib/cmap/connection_pool.js +113 -15
- package/lib/cmap/connection_pool.js.map +1 -1
- package/lib/cmap/connection_pool_events.js +3 -1
- package/lib/cmap/connection_pool_events.js.map +1 -1
- package/lib/cmap/errors.js +3 -3
- package/lib/cmap/errors.js.map +1 -1
- package/lib/cmap/message_stream.js +1 -1
- package/lib/cmap/message_stream.js.map +1 -1
- package/lib/cmap/metrics.js +62 -0
- package/lib/cmap/metrics.js.map +1 -0
- package/lib/cmap/stream_description.js +3 -1
- package/lib/cmap/stream_description.js.map +1 -1
- package/lib/cmap/wire_protocol/compression.js +22 -9
- package/lib/cmap/wire_protocol/compression.js.map +1 -1
- package/lib/cmap/wire_protocol/shared.js +1 -1
- package/lib/cmap/wire_protocol/shared.js.map +1 -1
- package/lib/collection.js +23 -18
- package/lib/collection.js.map +1 -1
- package/lib/connection_string.js +76 -30
- package/lib/connection_string.js.map +1 -1
- package/lib/cursor/abstract_cursor.js +75 -68
- package/lib/cursor/abstract_cursor.js.map +1 -1
- package/lib/cursor/aggregation_cursor.js +47 -9
- package/lib/cursor/aggregation_cursor.js.map +1 -1
- package/lib/cursor/find_cursor.js +53 -13
- package/lib/cursor/find_cursor.js.map +1 -1
- package/lib/db.js +21 -14
- package/lib/db.js.map +1 -1
- package/lib/deps.js +16 -5
- package/lib/deps.js.map +1 -1
- package/lib/encrypter.js +5 -8
- package/lib/encrypter.js.map +1 -1
- package/lib/error.js +230 -34
- package/lib/error.js.map +1 -1
- package/lib/explain.js +2 -2
- package/lib/explain.js.map +1 -1
- package/lib/gridfs/download.js +22 -47
- package/lib/gridfs/download.js.map +1 -1
- package/lib/gridfs/index.js +4 -3
- package/lib/gridfs/index.js.map +1 -1
- package/lib/gridfs/upload.js +13 -21
- package/lib/gridfs/upload.js.map +1 -1
- package/lib/index.js +27 -2
- package/lib/index.js.map +1 -1
- package/lib/logger.js +3 -2
- package/lib/logger.js.map +1 -1
- package/lib/mongo_client.js +5 -8
- package/lib/mongo_client.js.map +1 -1
- package/lib/mongo_types.js.map +1 -1
- package/lib/operations/add_user.js +2 -3
- package/lib/operations/add_user.js.map +1 -1
- package/lib/operations/aggregate.js +12 -9
- package/lib/operations/aggregate.js.map +1 -1
- package/lib/operations/command.js +5 -7
- package/lib/operations/command.js.map +1 -1
- package/lib/operations/common_functions.js +1 -1
- package/lib/operations/common_functions.js.map +1 -1
- package/lib/operations/connect.js +3 -2
- 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 +1 -1
- package/lib/operations/count_documents.js.map +1 -1
- package/lib/operations/delete.js +5 -5
- package/lib/operations/delete.js.map +1 -1
- package/lib/operations/distinct.js +2 -2
- package/lib/operations/distinct.js.map +1 -1
- package/lib/operations/estimated_document_count.js +5 -1
- package/lib/operations/estimated_document_count.js.map +1 -1
- package/lib/operations/eval.js.map +1 -1
- package/lib/operations/execute_operation.js +31 -17
- package/lib/operations/execute_operation.js.map +1 -1
- package/lib/operations/find.js +13 -9
- package/lib/operations/find.js.map +1 -1
- package/lib/operations/find_and_modify.js +9 -9
- package/lib/operations/find_and_modify.js.map +1 -1
- package/lib/operations/indexes.js +8 -3
- package/lib/operations/indexes.js.map +1 -1
- package/lib/operations/insert.js +5 -3
- package/lib/operations/insert.js.map +1 -1
- package/lib/operations/is_capped.js +2 -1
- package/lib/operations/is_capped.js.map +1 -1
- package/lib/operations/list_collections.js +6 -3
- package/lib/operations/list_collections.js.map +1 -1
- package/lib/operations/map_reduce.js +1 -1
- package/lib/operations/map_reduce.js.map +1 -1
- package/lib/operations/operation.js +3 -1
- package/lib/operations/operation.js.map +1 -1
- package/lib/operations/options_operation.js +2 -1
- package/lib/operations/options_operation.js.map +1 -1
- package/lib/operations/profiling_level.js +4 -2
- package/lib/operations/profiling_level.js.map +1 -1
- package/lib/operations/set_profiling_level.js +4 -2
- package/lib/operations/set_profiling_level.js.map +1 -1
- package/lib/operations/update.js +12 -12
- package/lib/operations/update.js.map +1 -1
- package/lib/operations/validate_collection.js +6 -5
- package/lib/operations/validate_collection.js.map +1 -1
- package/lib/promise_provider.js +1 -1
- package/lib/promise_provider.js.map +1 -1
- package/lib/read_preference.js +8 -8
- package/lib/read_preference.js.map +1 -1
- package/lib/sdam/common.js +12 -10
- package/lib/sdam/common.js.map +1 -1
- package/lib/sdam/server.js +90 -25
- package/lib/sdam/server.js.map +1 -1
- package/lib/sdam/server_description.js +9 -4
- package/lib/sdam/server_description.js.map +1 -1
- package/lib/sdam/server_selection.js +10 -4
- package/lib/sdam/server_selection.js.map +1 -1
- package/lib/sdam/srv_polling.js +1 -1
- package/lib/sdam/srv_polling.js.map +1 -1
- package/lib/sdam/topology.js +42 -21
- package/lib/sdam/topology.js.map +1 -1
- package/lib/sdam/topology_description.js +7 -3
- package/lib/sdam/topology_description.js.map +1 -1
- package/lib/sessions.js +132 -31
- package/lib/sessions.js.map +1 -1
- package/lib/sort.js +3 -3
- package/lib/sort.js.map +1 -1
- package/lib/transactions.js +15 -7
- package/lib/transactions.js.map +1 -1
- package/lib/utils.js +60 -20
- package/lib/utils.js.map +1 -1
- package/mongodb.d.ts +523 -138
- package/mongodb.ts34.d.ts +480 -141
- package/package.json +44 -48
- package/src/bson.ts +1 -0
- package/src/bulk/common.ts +83 -43
- package/src/bulk/ordered.ts +4 -3
- package/src/bulk/unordered.ts +4 -3
- package/src/change_stream.ts +46 -29
- package/src/cmap/auth/auth_provider.ts +3 -2
- package/src/cmap/auth/gssapi.ts +15 -5
- package/src/cmap/auth/mongo_credentials.ts +22 -8
- package/src/cmap/auth/mongocr.ts +3 -3
- package/src/cmap/auth/mongodb_aws.ts +52 -39
- package/src/cmap/auth/plain.ts +2 -2
- package/src/cmap/auth/scram.ts +23 -13
- package/src/cmap/auth/x509.ts +3 -3
- package/src/cmap/command_monitoring_events.ts +36 -14
- package/src/cmap/commands.ts +12 -6
- package/src/cmap/connect.ts +42 -12
- package/src/cmap/connection.ts +54 -62
- package/src/cmap/connection_pool.ts +141 -20
- package/src/cmap/connection_pool_events.ts +8 -1
- package/src/cmap/errors.ts +3 -4
- package/src/cmap/message_stream.ts +2 -4
- package/src/cmap/metrics.ts +58 -0
- package/src/cmap/stream_description.ts +6 -1
- package/src/cmap/wire_protocol/compression.ts +26 -13
- package/src/cmap/wire_protocol/shared.ts +4 -2
- package/src/collection.ts +75 -70
- package/src/connection_string.ts +97 -34
- package/src/cursor/abstract_cursor.ts +141 -104
- package/src/cursor/aggregation_cursor.ts +34 -20
- package/src/cursor/find_cursor.ts +41 -21
- package/src/db.ts +19 -18
- package/src/deps.ts +110 -22
- package/src/encrypter.ts +6 -12
- package/src/error.ts +264 -48
- package/src/explain.ts +3 -3
- package/src/gridfs/download.ts +48 -53
- package/src/gridfs/index.ts +5 -4
- package/src/gridfs/upload.ts +32 -33
- package/src/index.ts +42 -4
- package/src/logger.ts +6 -3
- package/src/mongo_client.ts +20 -23
- package/src/mongo_types.ts +19 -20
- package/src/operations/add_user.ts +4 -5
- package/src/operations/aggregate.ts +18 -17
- package/src/operations/command.ts +7 -10
- package/src/operations/common_functions.ts +2 -3
- package/src/operations/connect.ts +4 -3
- package/src/operations/count.ts +2 -2
- package/src/operations/count_documents.ts +2 -2
- package/src/operations/delete.ts +8 -6
- package/src/operations/distinct.ts +5 -3
- package/src/operations/estimated_document_count.ts +5 -1
- package/src/operations/eval.ts +1 -1
- package/src/operations/execute_operation.ts +41 -20
- package/src/operations/find.ts +25 -16
- package/src/operations/find_and_modify.ts +12 -10
- package/src/operations/indexes.ts +39 -8
- package/src/operations/insert.ts +7 -4
- package/src/operations/is_capped.ts +3 -2
- package/src/operations/list_collections.ts +9 -6
- package/src/operations/map_reduce.ts +4 -2
- package/src/operations/operation.ts +7 -2
- package/src/operations/options_operation.ts +3 -2
- package/src/operations/profiling_level.ts +5 -3
- package/src/operations/set_profiling_level.ts +9 -3
- package/src/operations/update.ts +17 -13
- package/src/operations/validate_collection.ts +7 -6
- package/src/promise_provider.ts +2 -2
- package/src/read_preference.ts +11 -9
- package/src/sdam/common.ts +11 -9
- package/src/sdam/server.ts +168 -69
- package/src/sdam/server_description.ts +16 -4
- package/src/sdam/server_selection.ts +15 -7
- package/src/sdam/srv_polling.ts +2 -2
- package/src/sdam/topology.ts +67 -36
- package/src/sdam/topology_description.ts +11 -4
- package/src/sessions.ts +194 -37
- package/src/sort.ts +6 -4
- package/src/transactions.ts +18 -9
- package/src/utils.ts +73 -20
- package/HISTORY.md +0 -2993
- package/lib/operations/find_one.js +0 -34
- package/lib/operations/find_one.js.map +0 -1
- package/src/operations/find_one.ts +0 -43
package/src/sdam/topology.ts
CHANGED
|
@@ -11,7 +11,13 @@ import {
|
|
|
11
11
|
} from '../sessions';
|
|
12
12
|
import { SrvPoller, SrvPollingEvent } from './srv_polling';
|
|
13
13
|
import { CMAP_EVENTS, ConnectionPoolEvents } from '../cmap/connection_pool';
|
|
14
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
MongoServerSelectionError,
|
|
16
|
+
MongoCompatibilityError,
|
|
17
|
+
MongoDriverError,
|
|
18
|
+
MongoTopologyClosedError,
|
|
19
|
+
MongoRuntimeError
|
|
20
|
+
} from '../error';
|
|
15
21
|
import { readPreferenceServerSelector, ServerSelector } from './server_selection';
|
|
16
22
|
import {
|
|
17
23
|
makeStateMachine,
|
|
@@ -28,7 +34,7 @@ import {
|
|
|
28
34
|
ServerType,
|
|
29
35
|
ClusterTime,
|
|
30
36
|
TimerQueue,
|
|
31
|
-
|
|
37
|
+
_advanceClusterTime,
|
|
32
38
|
drainTimerQueue,
|
|
33
39
|
clearAndRemoveTimerFrom,
|
|
34
40
|
STATE_CLOSED,
|
|
@@ -146,6 +152,7 @@ export interface TopologyOptions extends BSONSerializeOptions, ServerOptions {
|
|
|
146
152
|
srvPoller?: SrvPoller;
|
|
147
153
|
/** Indicates that a client should directly connect to a node without attempting to discover its topology type */
|
|
148
154
|
directConnection: boolean;
|
|
155
|
+
loadBalanced: boolean;
|
|
149
156
|
metadata: ClientMetadata;
|
|
150
157
|
/** MongoDB server API version */
|
|
151
158
|
serverApi?: ServerApi;
|
|
@@ -248,6 +255,7 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
|
|
|
248
255
|
retryWrites: DEFAULT_OPTIONS.get('retryWrites'),
|
|
249
256
|
serverSelectionTimeoutMS: DEFAULT_OPTIONS.get('serverSelectionTimeoutMS'),
|
|
250
257
|
directConnection: DEFAULT_OPTIONS.get('directConnection'),
|
|
258
|
+
loadBalanced: DEFAULT_OPTIONS.get('loadBalanced'),
|
|
251
259
|
metadata: DEFAULT_OPTIONS.get('metadata'),
|
|
252
260
|
monitorCommands: DEFAULT_OPTIONS.get('monitorCommands'),
|
|
253
261
|
tls: DEFAULT_OPTIONS.get('tls'),
|
|
@@ -274,7 +282,8 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
|
|
|
274
282
|
} else if (seed instanceof HostAddress) {
|
|
275
283
|
seedlist.push(seed);
|
|
276
284
|
} else {
|
|
277
|
-
|
|
285
|
+
// FIXME(NODE-3483): May need to be a MongoParseError
|
|
286
|
+
throw new MongoRuntimeError(`Topology cannot be constructed from ${JSON.stringify(seed)}`);
|
|
278
287
|
}
|
|
279
288
|
}
|
|
280
289
|
|
|
@@ -325,7 +334,7 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
|
|
|
325
334
|
detectSrvRecords: ev => this.detectSrvRecords(ev)
|
|
326
335
|
};
|
|
327
336
|
|
|
328
|
-
if (options.srvHost) {
|
|
337
|
+
if (options.srvHost && !options.loadBalanced) {
|
|
329
338
|
this.s.srvPoller =
|
|
330
339
|
options.srvPoller ??
|
|
331
340
|
new SrvPoller({
|
|
@@ -379,6 +388,10 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
|
|
|
379
388
|
return this.s.description;
|
|
380
389
|
}
|
|
381
390
|
|
|
391
|
+
get loadBalanced(): boolean {
|
|
392
|
+
return this.s.options.loadBalanced;
|
|
393
|
+
}
|
|
394
|
+
|
|
382
395
|
get capabilities(): ServerCapabilities {
|
|
383
396
|
return new ServerCapabilities(this.lastIsMaster());
|
|
384
397
|
}
|
|
@@ -411,7 +424,19 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
|
|
|
411
424
|
);
|
|
412
425
|
|
|
413
426
|
// connect all known servers, then attempt server selection to connect
|
|
414
|
-
|
|
427
|
+
const serverDescriptions = Array.from(this.s.description.servers.values());
|
|
428
|
+
connectServers(this, serverDescriptions);
|
|
429
|
+
|
|
430
|
+
// In load balancer mode we need to fake a server description getting
|
|
431
|
+
// emitted from the monitor, since the monitor doesn't exist.
|
|
432
|
+
if (this.s.options.loadBalanced) {
|
|
433
|
+
for (const description of serverDescriptions) {
|
|
434
|
+
const newDescription = new ServerDescription(description.hostAddress, undefined, {
|
|
435
|
+
loadBalanced: this.s.options.loadBalanced
|
|
436
|
+
});
|
|
437
|
+
this.serverUpdateHandler(newDescription);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
415
440
|
|
|
416
441
|
const readPreference = options.readPreference ?? ReadPreference.primary;
|
|
417
442
|
this.selectServer(readPreferenceServerSelector(readPreference), options, (err, server) => {
|
|
@@ -472,7 +497,7 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
|
|
|
472
497
|
|
|
473
498
|
stateTransition(this, STATE_CLOSING);
|
|
474
499
|
|
|
475
|
-
drainWaitQueue(this[kWaitQueue], new
|
|
500
|
+
drainWaitQueue(this[kWaitQueue], new MongoTopologyClosedError());
|
|
476
501
|
drainTimerQueue(this.s.connectionTimers);
|
|
477
502
|
|
|
478
503
|
if (this.s.srvPoller) {
|
|
@@ -482,28 +507,30 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
|
|
|
482
507
|
|
|
483
508
|
this.removeListener(Topology.TOPOLOGY_DESCRIPTION_CHANGED, this.s.detectShardedTopology);
|
|
484
509
|
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
510
|
+
eachAsync(
|
|
511
|
+
Array.from(this.s.sessions.values()),
|
|
512
|
+
(session, cb) => session.endSession(cb),
|
|
513
|
+
() => {
|
|
514
|
+
this.s.sessionPool.endAllPooledSessions(() => {
|
|
515
|
+
eachAsync(
|
|
516
|
+
Array.from(this.s.servers.values()),
|
|
517
|
+
(server, cb) => destroyServer(server, this, options, cb),
|
|
518
|
+
err => {
|
|
519
|
+
this.s.servers.clear();
|
|
520
|
+
|
|
521
|
+
// emit an event for close
|
|
522
|
+
this.emit(Topology.TOPOLOGY_CLOSED, new TopologyClosedEvent(this.s.id));
|
|
523
|
+
|
|
524
|
+
stateTransition(this, STATE_CLOSED);
|
|
525
|
+
|
|
526
|
+
if (typeof callback === 'function') {
|
|
527
|
+
callback(err);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
);
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
);
|
|
507
534
|
}
|
|
508
535
|
|
|
509
536
|
/**
|
|
@@ -610,7 +637,7 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
|
|
|
610
637
|
* @returns Whether sessions are supported on the current topology
|
|
611
638
|
*/
|
|
612
639
|
hasSessionSupport(): boolean {
|
|
613
|
-
return this.description.logicalSessionTimeoutMinutes != null;
|
|
640
|
+
return this.loadBalanced || this.description.logicalSessionTimeoutMinutes != null;
|
|
614
641
|
}
|
|
615
642
|
|
|
616
643
|
/** Start a logical session */
|
|
@@ -680,7 +707,7 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
|
|
|
680
707
|
// value of the clusterTime embedded field."
|
|
681
708
|
const clusterTime = serverDescription.$clusterTime;
|
|
682
709
|
if (clusterTime) {
|
|
683
|
-
|
|
710
|
+
_advanceClusterTime(this, clusterTime);
|
|
684
711
|
}
|
|
685
712
|
|
|
686
713
|
// If we already know all the information contained in this updated description, then
|
|
@@ -692,7 +719,7 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
|
|
|
692
719
|
// first update the TopologyDescription
|
|
693
720
|
this.s.description = this.s.description.update(serverDescription);
|
|
694
721
|
if (this.s.description.compatibilityError) {
|
|
695
|
-
this.emit(Topology.ERROR, new
|
|
722
|
+
this.emit(Topology.ERROR, new MongoCompatibilityError(this.s.description.compatibilityError));
|
|
696
723
|
return;
|
|
697
724
|
}
|
|
698
725
|
|
|
@@ -749,8 +776,11 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
|
|
|
749
776
|
return this.s.state === STATE_CLOSED;
|
|
750
777
|
}
|
|
751
778
|
|
|
779
|
+
/**
|
|
780
|
+
* @deprecated This function is deprecated and will be removed in the next major version.
|
|
781
|
+
*/
|
|
752
782
|
unref(): void {
|
|
753
|
-
emitWarning('
|
|
783
|
+
emitWarning('`unref` is a noop and will be removed in the next major version');
|
|
754
784
|
}
|
|
755
785
|
|
|
756
786
|
// NOTE: There are many places in code where we explicitly check the last isMaster
|
|
@@ -830,6 +860,10 @@ function topologyTypeFromOptions(options?: TopologyOptions) {
|
|
|
830
860
|
return TopologyType.ReplicaSetNoPrimary;
|
|
831
861
|
}
|
|
832
862
|
|
|
863
|
+
if (options?.loadBalanced) {
|
|
864
|
+
return TopologyType.LoadBalanced;
|
|
865
|
+
}
|
|
866
|
+
|
|
833
867
|
return TopologyType.Unknown;
|
|
834
868
|
}
|
|
835
869
|
|
|
@@ -954,10 +988,7 @@ function drainWaitQueue(queue: Denque<ServerSelectionRequest>, err?: MongoDriver
|
|
|
954
988
|
|
|
955
989
|
function processWaitQueue(topology: Topology) {
|
|
956
990
|
if (topology.s.state === STATE_CLOSED) {
|
|
957
|
-
drainWaitQueue(
|
|
958
|
-
topology[kWaitQueue],
|
|
959
|
-
new MongoDriverError('Topology is closed, please connect')
|
|
960
|
-
);
|
|
991
|
+
drainWaitQueue(topology[kWaitQueue], new MongoTopologyClosedError());
|
|
961
992
|
return;
|
|
962
993
|
}
|
|
963
994
|
|
|
@@ -3,7 +3,7 @@ import * as WIRE_CONSTANTS from '../cmap/wire_protocol/constants';
|
|
|
3
3
|
import { TopologyType, ServerType } from './common';
|
|
4
4
|
import type { ObjectId, Document } from '../bson';
|
|
5
5
|
import type { SrvPollingEvent } from './srv_polling';
|
|
6
|
-
import {
|
|
6
|
+
import { MongoError, MongoRuntimeError } from '../error';
|
|
7
7
|
|
|
8
8
|
// constants related to compatibility checks
|
|
9
9
|
const MIN_SUPPORTED_SERVER_VERSION = WIRE_CONSTANTS.MIN_SUPPORTED_SERVER_VERSION;
|
|
@@ -85,7 +85,13 @@ export class TopologyDescription {
|
|
|
85
85
|
|
|
86
86
|
// determine server compatibility
|
|
87
87
|
for (const serverDescription of this.servers.values()) {
|
|
88
|
-
|
|
88
|
+
// Load balancer mode is always compatible.
|
|
89
|
+
if (
|
|
90
|
+
serverDescription.type === ServerType.Unknown ||
|
|
91
|
+
serverDescription.type === ServerType.LoadBalancer
|
|
92
|
+
) {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
89
95
|
|
|
90
96
|
if (serverDescription.minWireVersion > MAX_SUPPORTED_WIRE_VERSION) {
|
|
91
97
|
this.compatible = false;
|
|
@@ -113,7 +119,7 @@ export class TopologyDescription {
|
|
|
113
119
|
break;
|
|
114
120
|
}
|
|
115
121
|
|
|
116
|
-
if (this.logicalSessionTimeoutMinutes
|
|
122
|
+
if (this.logicalSessionTimeoutMinutes == null) {
|
|
117
123
|
// First server with a non null logicalSessionsTimeout
|
|
118
124
|
this.logicalSessionTimeoutMinutes = server.logicalSessionTimeoutMinutes;
|
|
119
125
|
continue;
|
|
@@ -431,7 +437,8 @@ function updateRsWithPrimaryFromMember(
|
|
|
431
437
|
setName?: string
|
|
432
438
|
): TopologyType {
|
|
433
439
|
if (setName == null) {
|
|
434
|
-
|
|
440
|
+
// TODO(NODE-3483): should be an appropriate runtime error
|
|
441
|
+
throw new MongoRuntimeError('Argument "setName" is required if connected to a replica set');
|
|
435
442
|
}
|
|
436
443
|
|
|
437
444
|
if (
|