Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions src/cmap/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
private get supportsOpMsg(): boolean {
return (
this.description != null &&
// TODO(NODE-6672,NODE-6287): This guard is primarily for maxWireVersion = 0
maxWireVersion(this) >= 6 &&
!this.description.__nodejs_mock_server__
);
Expand Down Expand Up @@ -880,12 +881,6 @@ export class CryptoConnection extends Connection {
return await super.command<T>(ns, cmd, options, responseType);
}

if (serverWireVersion < 8) {
throw new MongoCompatibilityError(
'Auto-encryption requires a minimum MongoDB version of 4.2'
);
}

// Save sort or indexKeys based on the command being run
// the encrypt API serializes our JS objects to BSON to pass to the native code layer
// and then deserializes the encrypted result, the protocol level components
Expand Down
5 changes: 2 additions & 3 deletions src/cursor/change_stream_cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class ChangeStreamCursor<
} else {
options.resumeAfter = this.resumeToken;
}
} else if (this.startAtOperationTime != null && maxWireVersion(this.server) >= 7) {
} else if (this.startAtOperationTime != null) {
options.startAtOperationTime = this.startAtOperationTime;
}

Expand Down Expand Up @@ -145,8 +145,7 @@ export class ChangeStreamCursor<
if (
this.startAtOperationTime == null &&
this.changeStreamCursorOptions.resumeAfter == null &&
this.changeStreamCursorOptions.startAfter == null &&
this.maxWireVersion >= 7
this.changeStreamCursorOptions.startAfter == null
) {
this.startAtOperationTime = response.operationTime;
}
Expand Down
11 changes: 2 additions & 9 deletions src/operations/aggregate.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { type Connection } from '..';
import type { Document } from '../bson';
import { CursorResponse, ExplainedCursorResponse } from '../cmap/wire_protocol/responses';
import { type CursorTimeoutMode } from '../cursor/abstract_cursor';
import { MongoInvalidArgumentError } from '../error';
import { type ExplainOptions } from '../explain';
import { maxWireVersion, type MongoDBNamespace } from '../utils';
import { type MongoDBNamespace } from '../utils';
import { WriteConcern } from '../write_concern';
import { type CollationOptions, CommandOperation, type CommandOperationOptions } from './command';
import { Aspect, defineAspects, type Hint } from './operation';

/** @internal */
export const DB_AGGREGATE_COLLECTION = 1 as const;
const MIN_WIRE_VERSION_$OUT_READ_CONCERN_SUPPORT = 8;

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

override buildCommandDocument(connection: Connection): Document {
override buildCommandDocument(): Document {
const options = this.options;
const serverWireVersion = maxWireVersion(connection);
const command: Document = { aggregate: this.target, pipeline: this.pipeline };

if (this.hasWriteStage && serverWireVersion < MIN_WIRE_VERSION_$OUT_READ_CONCERN_SUPPORT) {
this.readConcern = undefined;
}

if (this.hasWriteStage && this.writeConcern) {
WriteConcern.apply(command, this.writeConcern);
}
Expand Down
2 changes: 1 addition & 1 deletion src/operations/find_and_modify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export class FindAndModifyOperation extends CommandOperation<Document> {
command.comment = options.comment;
}

decorateWithCollation(command, this.collection, options);
decorateWithCollation(command, options);

if (options.hint) {
const unacknowledgedWrite = this.writeConcern?.w === 0;
Expand Down
3 changes: 3 additions & 0 deletions src/read_preference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ export class ReadPreference {
tags?: TagSet[];
hedge?: HedgeOptions;
maxStalenessSeconds?: number;
/**
* @deprecated This will be removed as dead code in the next major version.
*/
minWireVersion?: number;

public static PRIMARY = ReadPreferenceMode.primary;
Expand Down
2 changes: 1 addition & 1 deletion src/sdam/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ export class Server extends TypedEventEmitter<ServerEvents> {
} else {
if (isSDAMUnrecoverableError(error)) {
if (shouldHandleStateChangeError(this, error)) {
const shouldClearPool = maxWireVersion(this) <= 7 || isNodeShuttingDownError(error);
const shouldClearPool = isNodeShuttingDownError(error);
if (this.loadBalanced && connection && shouldClearPool) {
this.pool.clear({ serviceId: connection.serviceId });
}
Expand Down
13 changes: 1 addition & 12 deletions src/sdam/server_selection.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MongoCompatibilityError, MongoInvalidArgumentError } from '../error';
import { MongoInvalidArgumentError } from '../error';
import { ReadPreference } from '../read_preference';
import { ServerType, TopologyType } from './common';
import type { ServerDescription, TagSet } from './server_description';
Expand Down Expand Up @@ -273,17 +273,6 @@ export function readPreferenceServerSelector(readPreference: ReadPreference): Se
servers: ServerDescription[],
deprioritized: ServerDescription[] = []
): ServerDescription[] {
const commonWireVersion = topologyDescription.commonWireVersion;
if (
commonWireVersion &&
readPreference.minWireVersion &&
readPreference.minWireVersion > commonWireVersion
) {
throw new MongoCompatibilityError(
`Minimum wire version '${readPreference.minWireVersion}' required, but found '${commonWireVersion}'`
);
}

if (topologyDescription.type === TopologyType.LoadBalanced) {
return servers.filter(loadBalancerFilter);
}
Expand Down
21 changes: 12 additions & 9 deletions src/sdam/topology.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,10 @@ function isStaleServerDescription(
);
}

/** @public */
/**
* @public
* @deprecated This class will be removed as dead code in the next major version.
*/
export class ServerCapabilities {
maxWireVersion: number;
minWireVersion: number;
Expand All @@ -1115,37 +1118,37 @@ export class ServerCapabilities {
}

get hasAggregationCursor(): boolean {
return this.maxWireVersion >= 1;
return true;
}

get hasWriteCommands(): boolean {
return this.maxWireVersion >= 2;
return true;
}
get hasTextSearch(): boolean {
return this.minWireVersion >= 0;
return true;
}

get hasAuthCommands(): boolean {
return this.maxWireVersion >= 1;
return true;
}

get hasListCollectionsCommand(): boolean {
return this.maxWireVersion >= 3;
return true;
}

get hasListIndexesCommand(): boolean {
return this.maxWireVersion >= 3;
return true;
}

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

get commandsTakeWriteConcern(): boolean {
return this.maxWireVersion >= 5;
return true;
}

get commandsTakeCollation(): boolean {
return this.maxWireVersion >= 5;
return true;
}
}
15 changes: 0 additions & 15 deletions src/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Binary, type Document, Long, type Timestamp } from './bson';
import type { CommandOptions, Connection } from './cmap/connection';
import { ConnectionPoolMetrics } from './cmap/metrics';
import { type MongoDBResponse } from './cmap/wire_protocol/responses';
import { isSharded } from './cmap/wire_protocol/shared';
import { PINNED, UNPINNED } from './constants';
import type { AbstractCursor } from './cursor/abstract_cursor';
import {
Expand Down Expand Up @@ -42,7 +41,6 @@ import {
commandSupportsReadConcern,
isPromiseLike,
List,
maxWireVersion,
MongoDBNamespace,
noop,
now,
Expand All @@ -51,8 +49,6 @@ import {
} from './utils';
import { WriteConcern, type WriteConcernOptions, type WriteConcernSettings } from './write_concern';

const minWireVersionForShardedTransactions = 8;

/** @public */
export interface ClientSessionOptions {
/** Whether causal consistency should be enabled on this session */
Expand Down Expand Up @@ -405,17 +401,6 @@ export class ClientSession
this.unpin();
}

const topologyMaxWireVersion = maxWireVersion(this.client.topology);
if (
isSharded(this.client.topology) &&
topologyMaxWireVersion != null &&
topologyMaxWireVersion < minWireVersionForShardedTransactions
) {
throw new MongoCompatibilityError(
'Transactions are not supported on sharded clusters in MongoDB < 4.2.'
);
}

this.commitAttempted = false;
// increment txnNumber
this.incrementTransactionNumber();
Expand Down
14 changes: 2 additions & 12 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import type { Db } from './db';
import {
type AnyError,
MongoAPIError,
MongoCompatibilityError,
MongoInvalidArgumentError,
MongoNetworkTimeoutError,
MongoNotConnectedError,
Expand Down Expand Up @@ -206,18 +205,9 @@ export function isPromiseLike<T = unknown>(value?: unknown): value is PromiseLik
* @param target - target of command
* @param options - options containing collation settings
*/
export function decorateWithCollation(
command: Document,
target: MongoClient | Db | Collection,
options: AnyOptions
): void {
const capabilities = getTopology(target).capabilities;
export function decorateWithCollation(command: Document, options: AnyOptions): void {
if (options.collation && typeof options.collation === 'object') {
if (capabilities && capabilities.commandsTakeCollation) {
command.collation = options.collation;
} else {
throw new MongoCompatibilityError(`Current topology does not support collation`);
}
command.collation = options.collation;
}
}

Expand Down
60 changes: 0 additions & 60 deletions test/unit/change_stream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,36 +184,6 @@ describe('ChangeStreamCursor', function () {
expect(cursor.resumeOptions).to.haveOwnProperty('startAtOperationTime');
});
});

context('when the maxWireVersion < 7', function () {
let cursor: ChangeStreamCursor;
beforeEach(function () {
cursor = new ChangeStreamCursor(
new MongoClient('mongodb://localhost:27027'),
new MongoDBNamespace('db', 'collection'),
[],
{
startAfter: 'start after',
resumeAfter: 'resume after',
startAtOperationTime: new Timestamp(Long.ZERO)
}
);
cursor.resumeToken = null;
sinon.stub(cursor, 'server').get(() => ({ hello: { maxWireVersion: 6 } }));
});

it('does NOT set the resumeAfter option', function () {
expect(cursor.resumeOptions).not.to.haveOwnProperty('resumeAfter');
});

it('does NOT set the startAfter option', function () {
expect(cursor.resumeOptions).not.to.haveOwnProperty('startAfter');
});

it('does NOT set the startAtOperationTime option', function () {
expect(cursor.resumeOptions).not.to.haveOwnProperty('startAtOperationTime');
});
});
});

context('when the cursor does NOT have a saved operation time', function () {
Expand Down Expand Up @@ -266,36 +236,6 @@ describe('ChangeStreamCursor', function () {
expect(cursor.resumeOptions).not.to.haveOwnProperty('startAtOperationTime');
});
});

context('when the maxWireVersion < 7', function () {
let cursor: ChangeStreamCursor;
beforeEach(function () {
cursor = new ChangeStreamCursor(
new MongoClient('mongodb://localhost:27027'),
new MongoDBNamespace('db', 'collection'),
[],
{
startAfter: 'start after',
resumeAfter: 'resume after',
startAtOperationTime: new Timestamp(Long.ZERO)
}
);
cursor.resumeToken = null;
sinon.stub(cursor, 'server').get(() => ({ hello: { maxWireVersion: 6 } }));
});

it('does NOT set the resumeAfter option', function () {
expect(cursor.resumeOptions).not.to.haveOwnProperty('resumeAfter');
});

it('does NOT set the startAfter option', function () {
expect(cursor.resumeOptions).not.to.haveOwnProperty('startAfter');
});

it('does NOT set the startAtOperationTime option', function () {
expect(cursor.resumeOptions).not.to.haveOwnProperty('startAtOperationTime');
});
});
});
});
});
Expand Down