Skip to content
Merged
20 changes: 9 additions & 11 deletions src/bulk/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import type { Topology } from '../sdam/topology';
import { type Sort } from '../sort';
import { TimeoutContext } from '../timeout';
import {
applyRetryableWrites,
getTopology,
hasAtomicOperators,
maybeAddIdToDocuments,
Expand Down Expand Up @@ -527,15 +526,15 @@ async function executeCommands(
finalOptions.checkKeys = false;
}

if (finalOptions.retryWrites) {
if (bulkOperation.retryWrites) {
if (isUpdateBatch(batch)) {
finalOptions.retryWrites =
finalOptions.retryWrites && !batch.operations.some(op => op.multi);
bulkOperation.retryWrites =
bulkOperation.retryWrites && !batch.operations.some(op => op.multi);
}

if (isDeleteBatch(batch)) {
finalOptions.retryWrites =
finalOptions.retryWrites && !batch.operations.some(op => op.limit === 0);
bulkOperation.retryWrites =
bulkOperation.retryWrites && !batch.operations.some(op => op.limit === 0);
}
}

Expand Down Expand Up @@ -859,13 +858,16 @@ export abstract class BulkOperationBase {
s: BulkOperationPrivate;
operationId?: number;
private collection: Collection;
/** @internal */
retryWrites?: boolean;

/**
* Create a new OrderedBulkOperation or UnorderedBulkOperation instance
* @internal
*/
constructor(collection: Collection, options: BulkWriteOptions, isOrdered: boolean) {
this.collection = collection;
this.retryWrites = collection.db.options?.retryWrites;
// determine whether bulkOperation is ordered or unordered
this.isOrdered = isOrdered;

Expand Down Expand Up @@ -898,10 +900,6 @@ export abstract class BulkOperationBase {
// + 1 bytes for null terminator
const maxKeySize = (maxWriteBatchSize - 1).toString(10).length + 2;

// Final options for retryable writes
let finalOptions = Object.assign({}, options);
finalOptions = applyRetryableWrites(finalOptions, collection.db);

// Final results
const bulkResult: BulkResult = {
ok: 1,
Expand Down Expand Up @@ -943,7 +941,7 @@ export abstract class BulkOperationBase {
// Topology
topology,
// Options
options: finalOptions,
options: options,
// BSON options
bsonOptions: resolveBSONOptions(options),
// Current operation
Expand Down
18 changes: 1 addition & 17 deletions src/change_stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ import {
import { MongoClient } from './mongo_client';
import { type InferIdType, TypedEventEmitter } from './mongo_types';
import type { AggregateOptions } from './operations/aggregate';
import type { CollationOptions, OperationParent } from './operations/command';
import type { ReadPreference } from './read_preference';
import type { OperationParent } from './operations/command';
import { type AsyncDisposable, configureResourceManagement } from './resource_management';
import type { ServerSessionId } from './sessions';
import { CSOTTimeoutContext, type TimeoutContext } from './timeout';
Expand All @@ -45,21 +44,6 @@ const NO_RESUME_TOKEN_ERROR =
'A change stream document has been received that lacks a resume token (_id).';
const CHANGESTREAM_CLOSED_ERROR = 'ChangeStream is closed';

/**
* @public
* @deprecated Please use the ChangeStreamCursorOptions type instead.
*/
export interface ResumeOptions {
startAtOperationTime?: Timestamp;
batchSize?: number;
maxAwaitTimeMS?: number;
collation?: CollationOptions;
readPreference?: ReadPreference;
resumeAfter?: ResumeToken;
startAfter?: ResumeToken;
fullDocument?: string;
}

/**
* Represents the logical starting point for a new ChangeStream or resuming a ChangeStream on the server.
* @see https://www.mongodb.com/docs/manual/changeStreams/#std-label-change-stream-resume
Expand Down
1 change: 1 addition & 0 deletions src/cmap/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export interface ConnectionOptions
tls: boolean;
noDelay?: boolean;
socketTimeoutMS?: number;
/** @internal */
cancellationToken?: CancellationToken;
metadata: ClientMetadata;
/** @internal */
Expand Down
9 changes: 0 additions & 9 deletions src/cmap/connection_pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,6 @@ export const PoolState = Object.freeze({

type PoolState = (typeof PoolState)[keyof typeof PoolState];

/**
* @public
* @deprecated This interface is deprecated and will be removed in a future release as it is not used
* in the driver
*/
export interface CloseOptions {
force?: boolean;
}

/** @public */
export type ConnectionPoolEvents = {
connectionPoolCreated(event: ConnectionPoolCreatedEvent): void;
Expand Down
13 changes: 0 additions & 13 deletions src/cmap/handshake/client_metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,6 @@ export interface ClientMetadata {
};
}

/**
* @public
* @deprecated This interface will be made internal in the next major release.
*/
export interface ClientMetadataOptions {
driverInfo?: {
name?: string;
version?: string;
platform?: string;
};
appName?: string;
}

/** @internal */
export class LimitedSizeDocument {
private document = new Map();
Expand Down
2 changes: 2 additions & 0 deletions src/cmap/wire_protocol/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export const MIN_SUPPORTED_SERVER_VERSION = '4.2';
export const MAX_SUPPORTED_SERVER_VERSION = '8.2';
export const MIN_SUPPORTED_SNAPSHOT_READS_WIRE_VERSION = 13;
export const MIN_SUPPORTED_SNAPSHOT_READS_SERVER_VERSION = '5.0';
export const MIN_SUPPORTED_WIRE_VERSION = 8;
export const MAX_SUPPORTED_WIRE_VERSION = 27;
export const MIN_SUPPORTED_QE_WIRE_VERSION = 21;
Expand Down
2 changes: 1 addition & 1 deletion src/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ export class Collection<TSchema extends Document = Document> {
// Explicitly set the limit to 1 and singleBatch to true for all commands, per the spec.
// noCursorTimeout must be unset as well as batchSize.
// See: https://github.com/mongodb/specifications/blob/master/source/crud/crud.md#findone-api-details
const { batchSize: _batchSize, noCursorTimeout: _noCursorTimeout, ...opts } = options;
const { ...opts } = options;
opts.singleBatch = true;
const cursor = this.find(filter, opts).limit(1);
const result = await cursor.next();
Expand Down
10 changes: 0 additions & 10 deletions src/connection_string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1283,16 +1283,6 @@ export const OPTIONS = {
secureProtocol: { type: 'any' },
index: { type: 'any' },
// Legacy options from v3 era
useNewUrlParser: {
type: 'boolean',
deprecated:
'useNewUrlParser has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version'
} as OptionDescriptor,
useUnifiedTopology: {
type: 'boolean',
deprecated:
'useUnifiedTopology has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version'
} as OptionDescriptor,
__skipPingOnConnect: { type: 'boolean' }
} as Record<keyof MongoClientOptions, OptionDescriptor>;

Expand Down
4 changes: 0 additions & 4 deletions src/gridfs/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ export interface GridFSFile {
filename: string;
metadata?: Document;
uploadDate: Date;
/** @deprecated Will be removed in the next major version. */
contentType?: string;
/** @deprecated Will be removed in the next major version. */
aliases?: string[];
}

/** @internal */
Expand Down
22 changes: 0 additions & 22 deletions src/gridfs/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,6 @@ export interface GridFSBucketWriteStreamOptions extends WriteConcernOptions {
id?: ObjectId;
/** Object to store in the file document's `metadata` field */
metadata?: Document;
/**
* String to store in the file document's `contentType` field.
* @deprecated Will be removed in the next major version. Add a contentType field to the metadata document instead.
*/
contentType?: string;
/**
* Array of strings to store in the file document's `aliases` field.
* @deprecated Will be removed in the next major version. Add an aliases field to the metadata document instead.
*/
aliases?: string[];
/**
* @experimental
* Specifies the time an operation will run until it throws a timeout error
Expand Down Expand Up @@ -305,8 +295,6 @@ function checkDone(stream: GridFSBucketWriteStream, callback: Callback): void {
stream.length,
stream.chunkSizeBytes,
stream.filename,
stream.options.contentType,
stream.options.aliases,
stream.options.metadata
);

Expand Down Expand Up @@ -402,8 +390,6 @@ function createFilesDoc(
length: number,
chunkSize: number,
filename: string,
contentType?: string,
aliases?: string[],
metadata?: Document
): GridFSFile {
const ret: GridFSFile = {
Expand All @@ -414,14 +400,6 @@ function createFilesDoc(
filename
};

if (contentType) {
ret.contentType = contentType;
}

if (aliases) {
ret.aliases = aliases;
}

if (metadata) {
ret.metadata = metadata;
}
Expand Down
5 changes: 1 addition & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ export type {
ChangeStreamSplitEvent,
ChangeStreamUpdateDocument,
OperationTime,
ResumeOptions,
ResumeToken,
UpdateDescription
} from './change_stream';
Expand Down Expand Up @@ -307,15 +306,14 @@ export type {
ProxyOptions
} from './cmap/connection';
export type {
CloseOptions,
ConnectionPool,
ConnectionPoolEvents,
ConnectionPoolOptions,
PoolState,
WaitQueueMember,
WithConnectionCallback
} from './cmap/connection_pool';
export type { ClientMetadata, ClientMetadataOptions } from './cmap/handshake/client_metadata';
export type { ClientMetadata } from './cmap/handshake/client_metadata';
export type { ConnectionPoolMetrics } from './cmap/metrics';
export type { StreamDescription, StreamDescriptionOptions } from './cmap/stream_description';
export type { CompressorName } from './cmap/wire_protocol/compression';
Expand Down Expand Up @@ -598,7 +596,6 @@ export type { SrvPoller, SrvPollerEvents, SrvPollerOptions } from './sdam/srv_po
export type {
ConnectOptions,
SelectServerOptions,
ServerCapabilities,
ServerSelectionCallback,
ServerSelectionRequest,
Topology,
Expand Down
3 changes: 1 addition & 2 deletions src/mongo_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,7 @@ export class TypedEventEmitter<Events extends EventsDescription> extends EventEm
}

/**
* @public
* @deprecated Will be removed in favor of `AbortSignal` in the next major release.
* @internal
*/
export class CancellationToken extends TypedEventEmitter<{ cancel(): void }> {
constructor(...args: any[]) {
Expand Down
7 changes: 0 additions & 7 deletions src/operations/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,6 @@ export interface CommandOperationOptions
* In server versions 4.4 and above, 'comment' can be any valid BSON type.
*/
comment?: unknown;
/**
* @deprecated
* This option is deprecated and will be removed in a future release as it is not used
* in the driver. Use MongoClientOptions or connection string parameters instead.
* */
retryWrites?: boolean;

// Admin command overrides.
dbName?: string;
authdb?: string;
Expand Down
3 changes: 0 additions & 3 deletions src/operations/create_collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const ILLEGAL_COMMAND_FIELDS = new Set([
'timeoutMS',
'j',
'fsync',
'autoIndexId',
'pkFactory',
'raw',
'readPreference',
Expand Down Expand Up @@ -68,8 +67,6 @@ export interface ClusteredCollectionOptions extends Document {
export interface CreateCollectionOptions extends Omit<CommandOperationOptions, 'rawData'> {
/** Create a capped collection */
capped?: boolean;
/** @deprecated Create an index on the _id field of the document. This option is deprecated in MongoDB 3.2+ and will be removed once no longer supported by the server. */
autoIndexId?: boolean;
/** The size of the capped collection in bytes */
size?: number;
/** The maximum number of documents in the capped collection */
Expand Down
8 changes: 6 additions & 2 deletions src/operations/execute_operation.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { MIN_SUPPORTED_SNAPSHOT_READS_WIRE_VERSION } from '../cmap/wire_protocol/constants';
import {
isRetryableReadError,
isRetryableWriteError,
Expand Down Expand Up @@ -25,7 +26,7 @@ import {
import type { Topology } from '../sdam/topology';
import type { ClientSession } from '../sessions';
import { TimeoutContext } from '../timeout';
import { abortable, supportsRetryableWrites } from '../utils';
import { abortable, maxWireVersion, supportsRetryableWrites } from '../utils';
import { AggregateOperation } from './aggregate';
import { AbstractOperation, Aspect } from './operation';

Expand Down Expand Up @@ -81,7 +82,10 @@ export async function executeOperation<
session = client.startSession({ owner, explicit: false });
} else if (session.hasEnded) {
throw new MongoExpiredSessionError('Use of expired sessions is not permitted');
} else if (session.snapshotEnabled && !topology.capabilities.supportsSnapshotReads) {
} else if (
session.snapshotEnabled &&
maxWireVersion(topology) < MIN_SUPPORTED_SNAPSHOT_READS_WIRE_VERSION
) {
throw new MongoCompatibilityError('Snapshot reads require MongoDB 5.0 or later');
} else if (session.client !== client) {
throw new MongoInvalidArgumentError('ClientSession must be from the same MongoClient');
Expand Down
13 changes: 2 additions & 11 deletions src/operations/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ import { Aspect, defineAspects, type Hint } from './operation';

/**
* @public
* @typeParam TSchema - Unused schema definition, deprecated usage, only specify `FindOptions` with no generic
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export interface FindOptions<TSchema extends Document = Document>
export interface FindOptions
extends Omit<CommandOperationOptions, 'writeConcern' | 'explain'>,
AbstractCursorOptions {
/** Sets the limit of documents returned in the query. */
Expand Down Expand Up @@ -76,14 +74,7 @@ export interface FindOptions<TSchema extends Document = Document>
}

/** @public */
export interface FindOneOptions extends FindOptions {
/** @deprecated Will be removed in the next major version. User provided value will be ignored. */
batchSize?: number;
/** @deprecated Will be removed in the next major version. User provided value will be ignored. */
limit?: number;
/** @deprecated Will be removed in the next major version. User provided value will be ignored. */
noCursorTimeout?: boolean;
}
export type FindOneOptions = Omit<FindOptions, 'batchSize' | 'limit' | 'noCursorTimeout'>;

/** @internal */
export class FindOperation extends CommandOperation<CursorResponse> {
Expand Down
9 changes: 0 additions & 9 deletions src/read_preference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ 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;
public static PRIMARY_PREFERRED = ReadPreferenceMode.primaryPreferred;
Expand Down Expand Up @@ -100,7 +96,6 @@ export class ReadPreference {
this.tags = tags;
this.hedge = options?.hedge;
this.maxStalenessSeconds = undefined;
this.minWireVersion = undefined;

options = options ?? {};
if (options.maxStalenessSeconds != null) {
Expand All @@ -109,10 +104,6 @@ export class ReadPreference {
}

this.maxStalenessSeconds = options.maxStalenessSeconds;

// NOTE: The minimum required wire version is 5 for this read preference. If the existing
// topology has a lower value then a MongoError will be thrown during server selection.
this.minWireVersion = 5;
}

if (this.mode === ReadPreference.PRIMARY) {
Expand Down
Loading