Skip to content

Commit 14303bc

Browse files
authored
feat(NODE-7139): remove pre-4.2 logic and deprecate dead code (#4657)
1 parent c617294 commit 14303bc

File tree

11 files changed

+25
-128
lines changed

11 files changed

+25
-128
lines changed

src/cmap/connection.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
284284
private get supportsOpMsg(): boolean {
285285
return (
286286
this.description != null &&
287+
// TODO(NODE-6672,NODE-6287): This guard is primarily for maxWireVersion = 0
287288
maxWireVersion(this) >= 6 &&
288289
!this.description.__nodejs_mock_server__
289290
);
@@ -880,12 +881,6 @@ export class CryptoConnection extends Connection {
880881
return await super.command<T>(ns, cmd, options, responseType);
881882
}
882883

883-
if (serverWireVersion < 8) {
884-
throw new MongoCompatibilityError(
885-
'Auto-encryption requires a minimum MongoDB version of 4.2'
886-
);
887-
}
888-
889884
// Save sort or indexKeys based on the command being run
890885
// the encrypt API serializes our JS objects to BSON to pass to the native code layer
891886
// and then deserializes the encrypted result, the protocol level components

src/cursor/change_stream_cursor.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export class ChangeStreamCursor<
9393
} else {
9494
options.resumeAfter = this.resumeToken;
9595
}
96-
} else if (this.startAtOperationTime != null && maxWireVersion(this.server) >= 7) {
96+
} else if (this.startAtOperationTime != null) {
9797
options.startAtOperationTime = this.startAtOperationTime;
9898
}
9999

@@ -145,8 +145,7 @@ export class ChangeStreamCursor<
145145
if (
146146
this.startAtOperationTime == null &&
147147
this.changeStreamCursorOptions.resumeAfter == null &&
148-
this.changeStreamCursorOptions.startAfter == null &&
149-
this.maxWireVersion >= 7
148+
this.changeStreamCursorOptions.startAfter == null
150149
) {
151150
this.startAtOperationTime = response.operationTime;
152151
}

src/operations/aggregate.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
import { type Connection } from '..';
21
import type { Document } from '../bson';
32
import { CursorResponse, ExplainedCursorResponse } from '../cmap/wire_protocol/responses';
43
import { type CursorTimeoutMode } from '../cursor/abstract_cursor';
54
import { MongoInvalidArgumentError } from '../error';
65
import { type ExplainOptions } from '../explain';
7-
import { maxWireVersion, type MongoDBNamespace } from '../utils';
6+
import { type MongoDBNamespace } from '../utils';
87
import { WriteConcern } from '../write_concern';
98
import { type CollationOptions, CommandOperation, type CommandOperationOptions } from './command';
109
import { Aspect, defineAspects, type Hint } from './operation';
1110

1211
/** @internal */
1312
export const DB_AGGREGATE_COLLECTION = 1 as const;
14-
const MIN_WIRE_VERSION_$OUT_READ_CONCERN_SUPPORT = 8;
1513

1614
/** @public */
1715
export interface AggregateOptions extends Omit<CommandOperationOptions, 'explain'> {
@@ -107,15 +105,10 @@ export class AggregateOperation extends CommandOperation<CursorResponse> {
107105
this.pipeline.push(stage);
108106
}
109107

110-
override buildCommandDocument(connection: Connection): Document {
108+
override buildCommandDocument(): Document {
111109
const options = this.options;
112-
const serverWireVersion = maxWireVersion(connection);
113110
const command: Document = { aggregate: this.target, pipeline: this.pipeline };
114111

115-
if (this.hasWriteStage && serverWireVersion < MIN_WIRE_VERSION_$OUT_READ_CONCERN_SUPPORT) {
116-
this.readConcern = undefined;
117-
}
118-
119112
if (this.hasWriteStage && this.writeConcern) {
120113
WriteConcern.apply(command, this.writeConcern);
121114
}

src/operations/find_and_modify.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ export class FindAndModifyOperation extends CommandOperation<Document> {
188188
command.comment = options.comment;
189189
}
190190

191-
decorateWithCollation(command, this.collection, options);
191+
decorateWithCollation(command, options);
192192

193193
if (options.hint) {
194194
const unacknowledgedWrite = this.writeConcern?.w === 0;

src/read_preference.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ export class ReadPreference {
6363
tags?: TagSet[];
6464
hedge?: HedgeOptions;
6565
maxStalenessSeconds?: number;
66+
/**
67+
* @deprecated This will be removed as dead code in the next major version.
68+
*/
6669
minWireVersion?: number;
6770

6871
public static PRIMARY = ReadPreferenceMode.primary;

src/sdam/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ export class Server extends TypedEventEmitter<ServerEvents> {
414414
} else {
415415
if (isSDAMUnrecoverableError(error)) {
416416
if (shouldHandleStateChangeError(this, error)) {
417-
const shouldClearPool = maxWireVersion(this) <= 7 || isNodeShuttingDownError(error);
417+
const shouldClearPool = isNodeShuttingDownError(error);
418418
if (this.loadBalanced && connection && shouldClearPool) {
419419
this.pool.clear({ serviceId: connection.serviceId });
420420
}

src/sdam/server_selection.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MongoCompatibilityError, MongoInvalidArgumentError } from '../error';
1+
import { MongoInvalidArgumentError } from '../error';
22
import { ReadPreference } from '../read_preference';
33
import { ServerType, TopologyType } from './common';
44
import type { ServerDescription, TagSet } from './server_description';
@@ -273,17 +273,6 @@ export function readPreferenceServerSelector(readPreference: ReadPreference): Se
273273
servers: ServerDescription[],
274274
deprioritized: ServerDescription[] = []
275275
): ServerDescription[] {
276-
const commonWireVersion = topologyDescription.commonWireVersion;
277-
if (
278-
commonWireVersion &&
279-
readPreference.minWireVersion &&
280-
readPreference.minWireVersion > commonWireVersion
281-
) {
282-
throw new MongoCompatibilityError(
283-
`Minimum wire version '${readPreference.minWireVersion}' required, but found '${commonWireVersion}'`
284-
);
285-
}
286-
287276
if (topologyDescription.type === TopologyType.LoadBalanced) {
288277
return servers.filter(loadBalancerFilter);
289278
}

src/sdam/topology.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,10 @@ function isStaleServerDescription(
11041104
);
11051105
}
11061106

1107-
/** @public */
1107+
/**
1108+
* @public
1109+
* @deprecated This class will be removed as dead code in the next major version.
1110+
*/
11081111
export class ServerCapabilities {
11091112
maxWireVersion: number;
11101113
minWireVersion: number;
@@ -1115,37 +1118,37 @@ export class ServerCapabilities {
11151118
}
11161119

11171120
get hasAggregationCursor(): boolean {
1118-
return this.maxWireVersion >= 1;
1121+
return true;
11191122
}
11201123

11211124
get hasWriteCommands(): boolean {
1122-
return this.maxWireVersion >= 2;
1125+
return true;
11231126
}
11241127
get hasTextSearch(): boolean {
1125-
return this.minWireVersion >= 0;
1128+
return true;
11261129
}
11271130

11281131
get hasAuthCommands(): boolean {
1129-
return this.maxWireVersion >= 1;
1132+
return true;
11301133
}
11311134

11321135
get hasListCollectionsCommand(): boolean {
1133-
return this.maxWireVersion >= 3;
1136+
return true;
11341137
}
11351138

11361139
get hasListIndexesCommand(): boolean {
1137-
return this.maxWireVersion >= 3;
1140+
return true;
11381141
}
11391142

11401143
get supportsSnapshotReads(): boolean {
11411144
return this.maxWireVersion >= 13;
11421145
}
11431146

11441147
get commandsTakeWriteConcern(): boolean {
1145-
return this.maxWireVersion >= 5;
1148+
return true;
11461149
}
11471150

11481151
get commandsTakeCollation(): boolean {
1149-
return this.maxWireVersion >= 5;
1152+
return true;
11501153
}
11511154
}

src/sessions.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Binary, type Document, Long, type Timestamp } from './bson';
22
import type { CommandOptions, Connection } from './cmap/connection';
33
import { ConnectionPoolMetrics } from './cmap/metrics';
44
import { type MongoDBResponse } from './cmap/wire_protocol/responses';
5-
import { isSharded } from './cmap/wire_protocol/shared';
65
import { PINNED, UNPINNED } from './constants';
76
import type { AbstractCursor } from './cursor/abstract_cursor';
87
import {
@@ -42,7 +41,6 @@ import {
4241
commandSupportsReadConcern,
4342
isPromiseLike,
4443
List,
45-
maxWireVersion,
4644
MongoDBNamespace,
4745
noop,
4846
now,
@@ -51,8 +49,6 @@ import {
5149
} from './utils';
5250
import { WriteConcern, type WriteConcernOptions, type WriteConcernSettings } from './write_concern';
5351

54-
const minWireVersionForShardedTransactions = 8;
55-
5652
/** @public */
5753
export interface ClientSessionOptions {
5854
/** Whether causal consistency should be enabled on this session */
@@ -405,17 +401,6 @@ export class ClientSession
405401
this.unpin();
406402
}
407403

408-
const topologyMaxWireVersion = maxWireVersion(this.client.topology);
409-
if (
410-
isSharded(this.client.topology) &&
411-
topologyMaxWireVersion != null &&
412-
topologyMaxWireVersion < minWireVersionForShardedTransactions
413-
) {
414-
throw new MongoCompatibilityError(
415-
'Transactions are not supported on sharded clusters in MongoDB < 4.2.'
416-
);
417-
}
418-
419404
this.commitAttempted = false;
420405
// increment txnNumber
421406
this.incrementTransactionNumber();

src/utils.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import type { Db } from './db';
1919
import {
2020
type AnyError,
2121
MongoAPIError,
22-
MongoCompatibilityError,
2322
MongoInvalidArgumentError,
2423
MongoNetworkTimeoutError,
2524
MongoNotConnectedError,
@@ -206,18 +205,9 @@ export function isPromiseLike<T = unknown>(value?: unknown): value is PromiseLik
206205
* @param target - target of command
207206
* @param options - options containing collation settings
208207
*/
209-
export function decorateWithCollation(
210-
command: Document,
211-
target: MongoClient | Db | Collection,
212-
options: AnyOptions
213-
): void {
214-
const capabilities = getTopology(target).capabilities;
208+
export function decorateWithCollation(command: Document, options: AnyOptions): void {
215209
if (options.collation && typeof options.collation === 'object') {
216-
if (capabilities && capabilities.commandsTakeCollation) {
217-
command.collation = options.collation;
218-
} else {
219-
throw new MongoCompatibilityError(`Current topology does not support collation`);
220-
}
210+
command.collation = options.collation;
221211
}
222212
}
223213

0 commit comments

Comments
 (0)