Skip to content

Commit 7c8ff33

Browse files
chore(NODE-4641): remove wire version checks for unsupported servers (#3416)
Co-authored-by: Bailey Pearson <[email protected]>
1 parent 48fa588 commit 7c8ff33

File tree

8 files changed

+16
-132
lines changed

8 files changed

+16
-132
lines changed

src/operations/aggregate.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,8 @@ export class AggregateOperation<T = Document> extends CommandOperation<T> {
9999
this.readConcern = undefined;
100100
}
101101

102-
if (serverWireVersion >= 5) {
103-
if (this.hasWriteStage && this.writeConcern) {
104-
Object.assign(command, { writeConcern: this.writeConcern });
105-
}
102+
if (this.hasWriteStage && this.writeConcern) {
103+
Object.assign(command, { writeConcern: this.writeConcern });
106104
}
107105

108106
if (options.bypassDocumentValidation === true) {

src/operations/command.ts

+8-26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { BSONSerializeOptions, Document } from '../bson';
2-
import { MongoCompatibilityError, MongoInvalidArgumentError } from '../error';
2+
import { MongoInvalidArgumentError } from '../error';
33
import { Explain, ExplainOptions } from '../explain';
44
import type { Logger } from '../logger';
55
import { ReadConcern } from '../read_concern';
@@ -18,8 +18,6 @@ import { WriteConcern, WriteConcernOptions } from '../write_concern';
1818
import type { ReadConcernLike } from './../read_concern';
1919
import { AbstractOperation, Aspect, OperationOptions } from './operation';
2020

21-
const SUPPORTS_WRITE_CONCERN_AND_COLLATION = 5;
22-
2321
/** @public */
2422
export interface CollationOptions {
2523
locale: string;
@@ -152,40 +150,24 @@ export abstract class CommandOperation<T> extends AbstractOperation<T> {
152150
options.omitReadPreference = true;
153151
}
154152

155-
if (options.collation && serverWireVersion < SUPPORTS_WRITE_CONCERN_AND_COLLATION) {
156-
callback(
157-
new MongoCompatibilityError(
158-
`Server ${server.name}, which reports wire version ${serverWireVersion}, does not support collation`
159-
)
160-
);
161-
return;
162-
}
163-
164153
if (this.writeConcern && this.hasAspect(Aspect.WRITE_OPERATION) && !inTransaction) {
165154
Object.assign(cmd, { writeConcern: this.writeConcern });
166155
}
167156

168-
if (serverWireVersion >= SUPPORTS_WRITE_CONCERN_AND_COLLATION) {
169-
if (
170-
options.collation &&
171-
typeof options.collation === 'object' &&
172-
!this.hasAspect(Aspect.SKIP_COLLATION)
173-
) {
174-
Object.assign(cmd, { collation: options.collation });
175-
}
157+
if (
158+
options.collation &&
159+
typeof options.collation === 'object' &&
160+
!this.hasAspect(Aspect.SKIP_COLLATION)
161+
) {
162+
Object.assign(cmd, { collation: options.collation });
176163
}
177164

178165
if (typeof options.maxTimeMS === 'number') {
179166
cmd.maxTimeMS = options.maxTimeMS;
180167
}
181168

182169
if (this.hasAspect(Aspect.EXPLAINABLE) && this.explain) {
183-
if (serverWireVersion < 6 && cmd.aggregate) {
184-
// Prior to 3.6, with aggregate, verbosity is ignored, and we must pass in "explain: true"
185-
cmd.explain = true;
186-
} else {
187-
cmd = decorateWithExplain(cmd, this.explain);
188-
}
170+
cmd = decorateWithExplain(cmd, this.explain);
189171
}
190172

191173
server.command(this.ns, cmd, options, callback);

src/operations/delete.ts

+2-16
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { Collection } from '../collection';
33
import { MongoCompatibilityError, MongoServerError } from '../error';
44
import type { Server } from '../sdam/server';
55
import type { ClientSession } from '../sessions';
6-
import { Callback, collationNotSupported, maxWireVersion, MongoDBNamespace } from '../utils';
6+
import type { Callback, MongoDBNamespace } from '../utils';
77
import type { WriteConcernOptions } from '../write_concern';
88
import { CollationOptions, CommandOperation, CommandOperationOptions } from './command';
99
import { Aspect, defineAspects, Hint } from './operation';
@@ -82,28 +82,14 @@ export class DeleteOperation extends CommandOperation<Document> {
8282
command.comment = options.comment;
8383
}
8484

85-
if (options.explain != null && maxWireVersion(server) < 3) {
86-
return callback
87-
? callback(
88-
new MongoCompatibilityError(`Server ${server.name} does not support explain on delete`)
89-
)
90-
: undefined;
91-
}
92-
9385
const unacknowledgedWrite = this.writeConcern && this.writeConcern.w === 0;
94-
if (unacknowledgedWrite || maxWireVersion(server) < 5) {
86+
if (unacknowledgedWrite) {
9587
if (this.statements.find((o: Document) => o.hint)) {
9688
callback(new MongoCompatibilityError(`Servers < 3.4 do not support hint on delete`));
9789
return;
9890
}
9991
}
10092

101-
const statementWithCollation = this.statements.find(statement => !!statement.collation);
102-
if (statementWithCollation && collationNotSupported(server, statementWithCollation)) {
103-
callback(new MongoCompatibilityError(`Server ${server.name} does not support collation`));
104-
return;
105-
}
106-
10793
super.executeCommand(server, session, command, callback);
10894
}
10995
}

src/operations/find.ts

+2-27
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
import type { Document } from '../bson';
22
import type { Collection } from '../collection';
3-
import { MongoCompatibilityError, MongoInvalidArgumentError } from '../error';
3+
import { MongoInvalidArgumentError } from '../error';
44
import { ReadConcern } from '../read_concern';
55
import type { Server } from '../sdam/server';
66
import type { ClientSession } from '../sessions';
77
import { formatSort, Sort } from '../sort';
8-
import {
9-
Callback,
10-
decorateWithExplain,
11-
maxWireVersion,
12-
MongoDBNamespace,
13-
normalizeHintField
14-
} from '../utils';
8+
import { Callback, decorateWithExplain, MongoDBNamespace, normalizeHintField } from '../utils';
159
import { CollationOptions, CommandOperation, CommandOperationOptions } from './command';
1610
import { Aspect, defineAspects, Hint } from './operation';
1711

@@ -70,8 +64,6 @@ export interface FindOptions<TSchema extends Document = Document> extends Comman
7064
oplogReplay?: boolean;
7165
}
7266

73-
const SUPPORTS_WRITE_CONCERN_AND_COLLATION = 5;
74-
7567
/** @internal */
7668
export class FindOperation extends CommandOperation<Document> {
7769
override options: FindOptions;
@@ -113,24 +105,7 @@ export class FindOperation extends CommandOperation<Document> {
113105
): void {
114106
this.server = server;
115107

116-
const serverWireVersion = maxWireVersion(server);
117108
const options = this.options;
118-
if (options.allowDiskUse != null && serverWireVersion < 4) {
119-
callback(
120-
new MongoCompatibilityError('Option "allowDiskUse" is not supported on MongoDB < 3.2')
121-
);
122-
return;
123-
}
124-
125-
if (options.collation && serverWireVersion < SUPPORTS_WRITE_CONCERN_AND_COLLATION) {
126-
callback(
127-
new MongoCompatibilityError(
128-
`Server ${server.name}, which reports wire version ${serverWireVersion}, does not support collation`
129-
)
130-
);
131-
132-
return;
133-
}
134109

135110
let findCommand = makeFindCommand(this.ns, this.filter, options);
136111
if (this.explain) {

src/operations/find_and_modify.ts

-9
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,6 @@ class FindAndModifyOperation extends CommandOperation<Document> {
202202
cmd.hint = options.hint;
203203
}
204204

205-
if (this.explain && maxWireVersion(server) < 4) {
206-
callback(
207-
new MongoCompatibilityError(
208-
`Server ${server.name} does not support explain on findAndModify`
209-
)
210-
);
211-
return;
212-
}
213-
214205
// Execute the command
215206
super.executeCommand(server, session, cmd, (err, result) => {
216207
if (err) return callback(err);

src/operations/update.ts

+2-31
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,7 @@ import type { Collection } from '../collection';
33
import { MongoCompatibilityError, MongoInvalidArgumentError, MongoServerError } from '../error';
44
import type { Server } from '../sdam/server';
55
import type { ClientSession } from '../sessions';
6-
import {
7-
Callback,
8-
collationNotSupported,
9-
hasAtomicOperators,
10-
maxWireVersion,
11-
MongoDBNamespace
12-
} from '../utils';
6+
import { Callback, hasAtomicOperators, MongoDBNamespace } from '../utils';
137
import { CollationOptions, CommandOperation, CommandOperationOptions } from './command';
148
import { Aspect, defineAspects, Hint } from './operation';
159

@@ -113,37 +107,14 @@ export class UpdateOperation extends CommandOperation<Document> {
113107
command.comment = options.comment;
114108
}
115109

116-
const statementWithCollation = this.statements.find(statement => !!statement.collation);
117-
if (
118-
collationNotSupported(server, options) ||
119-
(statementWithCollation && collationNotSupported(server, statementWithCollation))
120-
) {
121-
callback(new MongoCompatibilityError(`Server ${server.name} does not support collation`));
122-
return;
123-
}
124-
125110
const unacknowledgedWrite = this.writeConcern && this.writeConcern.w === 0;
126-
if (unacknowledgedWrite || maxWireVersion(server) < 5) {
111+
if (unacknowledgedWrite) {
127112
if (this.statements.find((o: Document) => o.hint)) {
128113
callback(new MongoCompatibilityError(`Servers < 3.4 do not support hint on update`));
129114
return;
130115
}
131116
}
132117

133-
if (this.explain && maxWireVersion(server) < 3) {
134-
callback(
135-
new MongoCompatibilityError(`Server ${server.name} does not support explain on update`)
136-
);
137-
return;
138-
}
139-
140-
if (this.statements.some(statement => !!statement.arrayFilters) && maxWireVersion(server) < 6) {
141-
callback(
142-
new MongoCompatibilityError('Option "arrayFilters" is only supported on MongoDB 3.6+')
143-
);
144-
return;
145-
}
146-
147118
super.executeCommand(server, session, command, callback);
148119
}
149120
}

src/sdam/server.ts

-8
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import {
2323
isNetworkErrorBeforeHandshake,
2424
isNodeShuttingDownError,
2525
isSDAMUnrecoverableError,
26-
MongoCompatibilityError,
2726
MongoError,
2827
MongoErrorLabel,
2928
MongoInvalidArgumentError,
@@ -41,7 +40,6 @@ import type { ClientSession } from '../sessions';
4140
import { isTransactionCommand } from '../transactions';
4241
import {
4342
Callback,
44-
collationNotSupported,
4543
EventEmitterWithState,
4644
makeStateMachine,
4745
maxWireVersion,
@@ -314,12 +312,6 @@ export class Server extends TypedEventEmitter<ServerEvents> {
314312
delete finalOptions.readPreference;
315313
}
316314

317-
// error if collation not supported
318-
if (collationNotSupported(this, cmd)) {
319-
callback(new MongoCompatibilityError(`Server ${this.name} does not support collation`));
320-
return;
321-
}
322-
323315
const session = finalOptions.session;
324316
const conn = session?.pinnedConnection;
325317

src/utils.ts

-11
Original file line numberDiff line numberDiff line change
@@ -563,17 +563,6 @@ export function maxWireVersion(topologyOrServer?: Connection | Topology | Server
563563
return 0;
564564
}
565565

566-
/**
567-
* Checks that collation is supported by server.
568-
* @internal
569-
*
570-
* @param server - to check against
571-
* @param cmd - object where collation may be specified
572-
*/
573-
export function collationNotSupported(server: Server, cmd: Document): boolean {
574-
return cmd && cmd.collation && maxWireVersion(server) < 5;
575-
}
576-
577566
/**
578567
* Applies the function `eachFn` to each item in `arr`, in parallel.
579568
* @internal

0 commit comments

Comments
 (0)