From 50b8328b6cbb95715a23561be0240a31069453c7 Mon Sep 17 00:00:00 2001 From: Warren James Date: Tue, 15 Oct 2024 16:12:23 -0400 Subject: [PATCH 01/13] deprecate legacy timeout options; add logic to prefer timeoutMS --- src/connection_string.ts | 2 + src/cursor/abstract_cursor.ts | 2 + src/cursor/find_cursor.ts | 1 + src/cursor/run_command_cursor.ts | 6 ++- src/explain.ts | 3 +- src/mongo_client.ts | 6 ++- src/operations/aggregate.ts | 3 +- src/operations/command.ts | 2 + src/operations/count.ts | 3 +- src/operations/estimated_document_count.ts | 1 + src/operations/find.ts | 4 +- src/operations/get_more.ts | 2 +- src/sessions.ts | 55 +++++++++++++--------- src/utils.ts | 15 ++++-- src/write_concern.ts | 6 ++- 15 files changed, 73 insertions(+), 38 deletions(-) diff --git a/src/connection_string.ts b/src/connection_string.ts index f0b497ddf40..3aae2d0a654 100644 --- a/src/connection_string.ts +++ b/src/connection_string.ts @@ -1092,6 +1092,7 @@ export const OPTIONS = { type: 'string' }, socketTimeoutMS: { + deprecated: 'Please use timeoutMS instead', default: 0, type: 'uint' }, @@ -1162,6 +1163,7 @@ export const OPTIONS = { } }, waitQueueTimeoutMS: { + deprecated: 'Please use timeoutMS instead', default: 0, type: 'uint' }, diff --git a/src/cursor/abstract_cursor.ts b/src/cursor/abstract_cursor.ts index 96d28d05584..dd3c40bfab6 100644 --- a/src/cursor/abstract_cursor.ts +++ b/src/cursor/abstract_cursor.ts @@ -84,6 +84,7 @@ export interface AbstractCursorOptions extends BSONSerializeOptions { /** * When applicable `maxTimeMS` controls the amount of time the initial command * that constructs a cursor should take. (ex. find, aggregate, listCollections) + * @deprecated Will be removed in the next major version. Please use timeoutMS instead. */ maxTimeMS?: number; /** @@ -721,6 +722,7 @@ export abstract class AbstractCursor< * Set a maxTimeMS on the cursor query, allowing for hard timeout limits on queries (Only supported on MongoDB 2.6 or higher) * * @param value - Number of milliseconds to wait before aborting the query. + * @deprecated Will be removed in the next major version. Please use the timeoutMS option instead. */ maxTimeMS(value: number): this { this.throwIfInitialized(); diff --git a/src/cursor/find_cursor.ts b/src/cursor/find_cursor.ts index 469c27628a5..eff59402a82 100644 --- a/src/cursor/find_cursor.ts +++ b/src/cursor/find_cursor.ts @@ -333,6 +333,7 @@ export class FindCursor extends ExplainableCursor { * Set a maxTimeMS on the cursor query, allowing for hard timeout limits on queries (Only supported on MongoDB 2.6 or higher) * * @param value - Number of milliseconds to wait before aborting the query. + *@deprecated Will be removed in the next major version. Please use timeoutMS instead. */ override maxTimeMS(value: number): this { this.throwIfInitialized(); diff --git a/src/cursor/run_command_cursor.ts b/src/cursor/run_command_cursor.ts index 90e4a94fd42..839b5890099 100644 --- a/src/cursor/run_command_cursor.ts +++ b/src/cursor/run_command_cursor.ts @@ -48,6 +48,7 @@ export class RunCommandCursor extends AbstractCursor { /** * Controls the `getMore.maxTimeMS` field. Only valid when cursor is tailable await * @param maxTimeMS - the number of milliseconds to wait for new data + * @deprecated Will be removed in the next major version. Please use timeoutMS instead. */ public setMaxTimeMS(maxTimeMS: number): this { this.getMoreOptions.maxAwaitTimeMS = maxTimeMS; @@ -56,7 +57,7 @@ export class RunCommandCursor extends AbstractCursor { /** * Controls the `getMore.batchSize` field - * @param maxTimeMS - the number documents to return in the `nextBatch` + * @param batchSize - the number documents to return in the `nextBatch` */ public setBatchSize(batchSize: number): this { this.getMoreOptions.batchSize = batchSize; @@ -82,7 +83,8 @@ export class RunCommandCursor extends AbstractCursor { ); } - /** Unsupported for RunCommandCursor: maxTimeMS must be configured directly on command document */ + /** Unsupported for RunCommandCursor: maxTimeMS must be configured directly on command document + * @deprecated Will be removed in the next major version. */ public override maxTimeMS(_: number): never { throw new MongoAPIError( 'maxTimeMS must be configured on the command document directly, to configure getMore.maxTimeMS use cursor.setMaxTimeMS()' diff --git a/src/explain.ts b/src/explain.ts index 670bea53041..9fad7ad7c91 100644 --- a/src/explain.ts +++ b/src/explain.ts @@ -24,7 +24,8 @@ export type ExplainVerbosityLike = ExplainVerbosity | boolean; export interface ExplainCommandOptions { /** The explain verbosity for the command. */ verbosity: ExplainVerbosity; - /** The maxTimeMS setting for the command. */ + /** The maxTimeMS setting for the command. + * @deprecated Will be removed in the next major version. Please use timeoutMS instead.*/ maxTimeMS?: number; } diff --git a/src/mongo_client.ts b/src/mongo_client.ts index 569f0e97c79..ad72cc4539b 100644 --- a/src/mongo_client.ts +++ b/src/mongo_client.ts @@ -152,7 +152,8 @@ export interface MongoClientOptions extends BSONSerializeOptions, SupportedNodeC tlsInsecure?: boolean; /** The time in milliseconds to attempt a connection before timing out. */ connectTimeoutMS?: number; - /** The time in milliseconds to attempt a send or receive on a socket before the attempt times out. */ + /** The time in milliseconds to attempt a send or receive on a socket before the attempt times out. + * @deprecated Will be removed in the next major version. Please use timeoutMS instead */ socketTimeoutMS?: number; /** An array or comma-delimited string of compressors to enable network compression for communication between this client and a mongod/mongos instance. */ compressors?: CompressorName[] | string; @@ -176,7 +177,8 @@ export interface MongoClientOptions extends BSONSerializeOptions, SupportedNodeC maxConnecting?: number; /** The maximum number of milliseconds that a connection can remain idle in the pool before being removed and closed. */ maxIdleTimeMS?: number; - /** The maximum time in milliseconds that a thread can wait for a connection to become available. */ + /** The maximum time in milliseconds that a thread can wait for a connection to become available. + * @deprecated Will be removed in the next major version. Please use timeoutMS instead */ waitQueueTimeoutMS?: number; /** Specify a read concern for the collection (only MongoDB 3.2 or higher supported) */ readConcern?: ReadConcernLike; diff --git a/src/operations/aggregate.ts b/src/operations/aggregate.ts index 0e9fbb0b846..4f05e690bdb 100644 --- a/src/operations/aggregate.ts +++ b/src/operations/aggregate.ts @@ -26,7 +26,8 @@ export interface AggregateOptions extends Omit it returns as a real cursor on pre 2.6 it returns as an emulated cursor. */ cursor?: Document; - /** specifies a cumulative time limit in milliseconds for processing operations on the cursor. MongoDB interrupts the operation at the earliest following interrupt point. */ + /** specifies a cumulative time limit in milliseconds for processing operations on the cursor. MongoDB interrupts the operation at the earliest following interrupt point. + * @deprecated Will be removed in the next major version. Please use timeoutMS instead.*/ maxTimeMS?: number; /** The maximum amount of time for the server to wait on new documents to satisfy a tailable cursor query. */ maxAwaitTimeMS?: number; diff --git a/src/operations/command.ts b/src/operations/command.ts index bcd3919017b..02d2d22af50 100644 --- a/src/operations/command.ts +++ b/src/operations/command.ts @@ -40,6 +40,8 @@ export interface CommandOperationOptions readConcern?: ReadConcernLike; /** Collation */ collation?: CollationOptions; + /** + * @deprecated Will be removed in the next major version. Please use timeoutMS instead. */ maxTimeMS?: number; /** * Comment to apply to the operation. diff --git a/src/operations/count.ts b/src/operations/count.ts index 82330a11e76..da79a20e835 100644 --- a/src/operations/count.ts +++ b/src/operations/count.ts @@ -13,7 +13,8 @@ export interface CountOptions extends CommandOperationOptions { skip?: number; /** The maximum amounts to count before aborting. */ limit?: number; - /** Number of milliseconds to wait before aborting the query. */ + /** Number of milliseconds to wait before aborting the query. + * @deprecated Will be removed in the next major version. Please use timeoutMS instead. */ maxTimeMS?: number; /** An index name hint for the query. */ hint?: string | Document; diff --git a/src/operations/estimated_document_count.ts b/src/operations/estimated_document_count.ts index 5ab5aa4c305..79b58fbfe88 100644 --- a/src/operations/estimated_document_count.ts +++ b/src/operations/estimated_document_count.ts @@ -12,6 +12,7 @@ export interface EstimatedDocumentCountOptions extends CommandOperationOptions { * The maximum amount of time to allow the operation to run. * * This option is sent only if the caller explicitly provides a value. The default is to not send a value. + *@deprecated Will be removed in the next major version. Please use timeoutMS instead. */ maxTimeMS?: number; } diff --git a/src/operations/find.ts b/src/operations/find.ts index 1775ea6e07f..444466ac4f8 100644 --- a/src/operations/find.ts +++ b/src/operations/find.ts @@ -48,7 +48,8 @@ export interface FindOptions min?: Document; /** The exclusive upper bound for a specific index */ max?: Document; - /** Number of milliseconds to wait before aborting the query. */ + /** Number of milliseconds to wait before aborting the query. + * @deprecated Will be removed in the next major version. Please use timeoutMS instead. */ maxTimeMS?: number; /** The maximum amount of time for the server to wait on new documents to satisfy a tailable cursor query. Requires `tailable` and `awaitData` to be true */ maxAwaitTimeMS?: number; @@ -77,7 +78,6 @@ export interface FindOptions * @deprecated This API is deprecated in favor of `collection.find().explain()`. */ explain?: ExplainOptions['explain']; - /** @internal*/ timeoutMode?: CursorTimeoutMode; } diff --git a/src/operations/get_more.ts b/src/operations/get_more.ts index 34317d533b5..d4bf84e7446 100644 --- a/src/operations/get_more.ts +++ b/src/operations/get_more.ts @@ -17,7 +17,7 @@ export interface GetMoreOptions extends OperationOptions { * getMore only supports 'comment' in server versions 4.4 and above. */ comment?: unknown; - /** Number of milliseconds to wait before aborting the query. */ + /** Number of milliseconds to wait before aborting the query. maxTimeMS?: number; /** TODO(NODE-4413): Address bug with maxAwaitTimeMS not being passed in from the cursor correctly */ maxAwaitTimeMS?: number; diff --git a/src/sessions.ts b/src/sessions.ts index 434abc83ef5..de9c79072f9 100644 --- a/src/sessions.ts +++ b/src/sessions.ts @@ -487,13 +487,29 @@ export class ClientSession maxTimeMS?: number; } = { commitTransaction: 1 }; + const timeoutMS = + typeof options?.timeoutMS === 'number' + ? options.timeoutMS + : typeof this.timeoutMS === 'number' + ? this.timeoutMS + : null; + const wc = this.transaction.options.writeConcern ?? this.clientOptions?.writeConcern; if (wc != null) { - WriteConcern.apply(command, { wtimeoutMS: 10000, w: 'majority', ...wc }); + if (timeoutMS == null && this.timeoutContext == null) { + WriteConcern.apply(command, { wtimeoutMS: 10000, w: 'majority', ...wc }); + } else { + WriteConcern.apply(command, { w: 'majority', ...wc, wtimeoutMS: undefined }); + } } if (this.transaction.state === TxnState.TRANSACTION_COMMITTED || this.commitAttempted) { WriteConcern.apply(command, { wtimeoutMS: 10000, ...wc, w: 'majority' }); + if (timeoutMS == null && this.timeoutContext == null) { + WriteConcern.apply(command, { wtimeoutMS: 10000, ...wc, w: 'majority' }); + } else { + WriteConcern.apply(command, { w: 'majority', ...wc, wtimeoutMS: undefined }); + } } if (typeof this.transaction.options.maxTimeMS === 'number') { @@ -510,13 +526,6 @@ export class ClientSession bypassPinningCheck: true }); - const timeoutMS = - typeof options?.timeoutMS === 'number' - ? options.timeoutMS - : typeof this.timeoutMS === 'number' - ? this.timeoutMS - : null; - const timeoutContext = this.timeoutContext ?? (typeof timeoutMS === 'number' @@ -616,21 +625,6 @@ export class ClientSession recoveryToken?: Document; } = { abortTransaction: 1 }; - const wc = this.transaction.options.writeConcern ?? this.clientOptions?.writeConcern; - if (wc != null) { - WriteConcern.apply(command, { wtimeoutMS: 10000, w: 'majority', ...wc }); - } - - if (this.transaction.recoveryToken) { - command.recoveryToken = this.transaction.recoveryToken; - } - - const operation = new RunAdminCommandOperation(command, { - session: this, - readPreference: ReadPreference.primary, - bypassPinningCheck: true - }); - const timeoutMS = typeof options?.timeoutMS === 'number' ? options.timeoutMS @@ -649,6 +643,21 @@ export class ClientSession }) : null; + const wc = this.transaction.options.writeConcern ?? this.clientOptions?.writeConcern; + if (wc != null && timeoutMS == null) { + WriteConcern.apply(command, { wtimeoutMS: 10000, w: 'majority', ...wc }); + } + + if (this.transaction.recoveryToken) { + command.recoveryToken = this.transaction.recoveryToken; + } + + const operation = new RunAdminCommandOperation(command, { + session: this, + readPreference: ReadPreference.primary, + bypassPinningCheck: true + }); + try { await executeOperation(this.client, operation, timeoutContext); this.unpin(); diff --git a/src/utils.ts b/src/utils.ts index e4381908cc5..25d3b087825 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -516,20 +516,31 @@ export function resolveOptions( ): T { const result: T = Object.assign({}, options, resolveBSONOptions(options, parent)); + const timeoutMS = options?.timeoutMS ?? parent?.timeoutMS; // Users cannot pass a readConcern/writeConcern to operations in a transaction const session = options?.session; + if (!session?.inTransaction()) { const readConcern = ReadConcern.fromOptions(options) ?? parent?.readConcern; if (readConcern) { result.readConcern = readConcern; } - const writeConcern = WriteConcern.fromOptions(options) ?? parent?.writeConcern; + let writeConcern = WriteConcern.fromOptions(options) ?? parent?.writeConcern; if (writeConcern) { + if (timeoutMS != null) { + writeConcern = WriteConcern.fromOptions({ + ...writeConcern, + wtimeout: undefined, + wtimeoutMS: undefined + }); + } result.writeConcern = writeConcern; } } + result.timeoutMS = timeoutMS; + const readPreference = ReadPreference.fromOptions(options) ?? parent?.readPreference; if (readPreference) { result.readPreference = readPreference; @@ -542,8 +553,6 @@ export function resolveOptions( ); } - result.timeoutMS = options?.timeoutMS ?? parent?.timeoutMS; - return result; } diff --git a/src/write_concern.ts b/src/write_concern.ts index 390646a3be0..1406151c0d0 100644 --- a/src/write_concern.ts +++ b/src/write_concern.ts @@ -15,7 +15,8 @@ export interface WriteConcernOptions { export interface WriteConcernSettings { /** The write concern */ w?: W; - /** The write concern timeout */ + /** The write concern timeout + * @deprecated Will be removed in the next major version. Please use timeoutMS */ wtimeoutMS?: number; /** The journal write concern */ journal?: boolean; @@ -65,7 +66,8 @@ export class WriteConcern { readonly w?: W; /** Request acknowledgment that the write operation has been written to the on-disk journal */ readonly journal?: boolean; - /** Specify a time limit to prevent write operations from blocking indefinitely */ + /** Specify a time limit to prevent write operations from blocking indefinitely + * @deprecated Will be removed in the next major version. Please use timeoutMS */ readonly wtimeoutMS?: number; /** * Specify a time limit to prevent write operations from blocking indefinitely. From 36726ea6fa2372669812e5ec598f3992552d666a Mon Sep 17 00:00:00 2001 From: Warren James Date: Tue, 22 Oct 2024 13:37:49 -0400 Subject: [PATCH 02/13] unskip tests --- .../client_side_operations_timeout.spec.test.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/test/integration/client-side-operations-timeout/client_side_operations_timeout.spec.test.ts b/test/integration/client-side-operations-timeout/client_side_operations_timeout.spec.test.ts index c519da8039f..73939c18dd0 100644 --- a/test/integration/client-side-operations-timeout/client_side_operations_timeout.spec.test.ts +++ b/test/integration/client-side-operations-timeout/client_side_operations_timeout.spec.test.ts @@ -4,13 +4,7 @@ import * as semver from 'semver'; import { loadSpecTests } from '../../spec'; import { runUnifiedSuite } from '../../tools/unified-spec-runner/runner'; -const skippedSpecs = { - 'change-streams': 'TODO(NODE-6035)', - 'convenient-transactions': 'TODO(NODE-5687)', - 'deprecated-options': 'TODO(NODE-5689)', - 'tailable-awaitData': 'TODO(NODE-6035)', - 'tailable-non-awaitData': 'TODO(NODE-6035)' -}; +const skippedSpecs = {}; const skippedTests = { 'timeoutMS can be configured on a MongoClient - createChangeStream on client': 'TODO(NODE-6305)', From e105b80a6b06aa8c8ce245ef6a67fe782de2c098 Mon Sep 17 00:00:00 2001 From: Warren James Date: Tue, 22 Oct 2024 14:12:23 -0400 Subject: [PATCH 03/13] only unskip relevant tests --- .../client_side_operations_timeout.spec.test.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/integration/client-side-operations-timeout/client_side_operations_timeout.spec.test.ts b/test/integration/client-side-operations-timeout/client_side_operations_timeout.spec.test.ts index 73939c18dd0..6708d7da89f 100644 --- a/test/integration/client-side-operations-timeout/client_side_operations_timeout.spec.test.ts +++ b/test/integration/client-side-operations-timeout/client_side_operations_timeout.spec.test.ts @@ -4,7 +4,12 @@ import * as semver from 'semver'; import { loadSpecTests } from '../../spec'; import { runUnifiedSuite } from '../../tools/unified-spec-runner/runner'; -const skippedSpecs = {}; +const skippedSpecs = { + 'change-streams': 'TODO(NODE-6035)', + 'convenient-transactions': 'TODO(NODE-5687)', + 'tailable-awaitData': 'TODO(NODE-6035)', + 'tailable-non-awaitData': 'TODO(NODE-6035)' +}; const skippedTests = { 'timeoutMS can be configured on a MongoClient - createChangeStream on client': 'TODO(NODE-6305)', From d193d502a5ad7ab5460157d78a279fae115e27c4 Mon Sep 17 00:00:00 2001 From: Warren James Date: Tue, 22 Oct 2024 15:37:47 -0400 Subject: [PATCH 04/13] WIP --- src/cursor/aggregation_cursor.ts | 12 +++--------- src/cursor/find_cursor.ts | 13 +++---------- src/explain.ts | 7 ++++--- src/operations/command.ts | 6 +++--- src/operations/find.ts | 12 ++++-------- 5 files changed, 17 insertions(+), 33 deletions(-) diff --git a/src/cursor/aggregation_cursor.ts b/src/cursor/aggregation_cursor.ts index db7bd20b5fa..b42dc91ed5d 100644 --- a/src/cursor/aggregation_cursor.ts +++ b/src/cursor/aggregation_cursor.ts @@ -1,11 +1,11 @@ import type { Document } from '../bson'; import { MongoAPIError } from '../error'; import { + cleanUpExplainTimeoutOptions, Explain, ExplainableCursor, type ExplainCommandOptions, - type ExplainVerbosityLike, - validateExplainTimeoutOptions + type ExplainVerbosityLike } from '../explain'; import type { MongoClient } from '../mongo_client'; import { AggregateOperation, type AggregateOptions } from '../operations/aggregate'; @@ -75,13 +75,7 @@ export class AggregationCursor extends ExplainableCursor ...this.cursorOptions, session }; - try { - validateExplainTimeoutOptions(options, Explain.fromOptions(options)); - } catch { - throw new MongoAPIError( - 'timeoutMS cannot be used with explain when explain is specified in aggregateOptions' - ); - } + cleanUpExplainTimeoutOptions(options, Explain.fromOptions(options)); const aggregateOperation = new AggregateOperation(this.namespace, this.pipeline, options); diff --git a/src/cursor/find_cursor.ts b/src/cursor/find_cursor.ts index eff59402a82..1763f1578bc 100644 --- a/src/cursor/find_cursor.ts +++ b/src/cursor/find_cursor.ts @@ -2,11 +2,11 @@ import { type Document } from '../bson'; import { CursorResponse } from '../cmap/wire_protocol/responses'; import { MongoAPIError, MongoInvalidArgumentError, MongoTailableCursorError } from '../error'; import { + cleanUpExplainTimeoutOptions, Explain, ExplainableCursor, type ExplainCommandOptions, - type ExplainVerbosityLike, - validateExplainTimeoutOptions + type ExplainVerbosityLike } from '../explain'; import type { MongoClient } from '../mongo_client'; import type { CollationOptions } from '../operations/command'; @@ -75,13 +75,7 @@ export class FindCursor extends ExplainableCursor { session }; - try { - validateExplainTimeoutOptions(options, Explain.fromOptions(options)); - } catch { - throw new MongoAPIError( - 'timeoutMS cannot be used with explain when explain is specified in findOptions' - ); - } + cleanUpExplainTimeoutOptions(options, Explain.fromOptions(options)); const findOperation = new FindOperation(this.namespace, this.cursorFilter, options); @@ -333,7 +327,6 @@ export class FindCursor extends ExplainableCursor { * Set a maxTimeMS on the cursor query, allowing for hard timeout limits on queries (Only supported on MongoDB 2.6 or higher) * * @param value - Number of milliseconds to wait before aborting the query. - *@deprecated Will be removed in the next major version. Please use timeoutMS instead. */ override maxTimeMS(value: number): this { this.throwIfInitialized(); diff --git a/src/explain.ts b/src/explain.ts index 9fad7ad7c91..52a5e49a654 100644 --- a/src/explain.ts +++ b/src/explain.ts @@ -66,7 +66,7 @@ export interface ExplainOptions { /** @internal */ export class Explain { readonly verbosity: ExplainVerbosity; - readonly maxTimeMS?: number; + maxTimeMS?: number; private constructor(verbosity: ExplainVerbosityLike, maxTimeMS?: number) { if (typeof verbosity === 'boolean') { @@ -92,10 +92,11 @@ export class Explain { } } -export function validateExplainTimeoutOptions(options: Document, explain?: Explain) { +export function cleanUpExplainTimeoutOptions(options: Document, explain?: Explain) { const { maxTimeMS, timeoutMS } = options; if (timeoutMS != null && (maxTimeMS != null || explain?.maxTimeMS != null)) { - throw new MongoAPIError('Cannot use maxTimeMS with timeoutMS for explain commands.'); + if (maxTimeMS != null) delete options.maxTimeMS; + if (explain?.maxTimeMS != null) delete explain.maxTimeMS; } } diff --git a/src/operations/command.ts b/src/operations/command.ts index 02d2d22af50..1ad5884eb1f 100644 --- a/src/operations/command.ts +++ b/src/operations/command.ts @@ -2,10 +2,10 @@ import type { BSONSerializeOptions, Document } from '../bson'; import { type MongoDBResponseConstructor } from '../cmap/wire_protocol/responses'; import { MongoInvalidArgumentError } from '../error'; import { + cleanUpExplainTimeoutOptions, decorateWithExplain, Explain, - type ExplainOptions, - validateExplainTimeoutOptions + type ExplainOptions } from '../explain'; import { ReadConcern } from '../read_concern'; import type { ReadPreference } from '../read_preference'; @@ -99,7 +99,7 @@ export abstract class CommandOperation extends AbstractOperation { if (this.hasAspect(Aspect.EXPLAINABLE)) { this.explain = Explain.fromOptions(options); - validateExplainTimeoutOptions(this.options, this.explain); + cleanUpExplainTimeoutOptions(this.options, this.explain); } else if (options?.explain != null) { throw new MongoInvalidArgumentError(`Option "explain" is not supported on this command`); } diff --git a/src/operations/find.ts b/src/operations/find.ts index 444466ac4f8..833240e5161 100644 --- a/src/operations/find.ts +++ b/src/operations/find.ts @@ -2,11 +2,7 @@ import type { Document } from '../bson'; import { CursorResponse, ExplainedCursorResponse } from '../cmap/wire_protocol/responses'; import { type AbstractCursorOptions, type CursorTimeoutMode } from '../cursor/abstract_cursor'; import { MongoInvalidArgumentError } from '../error'; -import { - decorateWithExplain, - type ExplainOptions, - validateExplainTimeoutOptions -} from '../explain'; +import { cleanUpExplainTimeoutOptions, decorateWithExplain, type ExplainOptions } from '../explain'; import { ReadConcern } from '../read_concern'; import type { Server } from '../sdam/server'; import type { ClientSession } from '../sessions'; @@ -48,8 +44,7 @@ export interface FindOptions min?: Document; /** The exclusive upper bound for a specific index */ max?: Document; - /** Number of milliseconds to wait before aborting the query. - * @deprecated Will be removed in the next major version. Please use timeoutMS instead. */ + /** Number of milliseconds to wait before aborting the query. */ maxTimeMS?: number; /** The maximum amount of time for the server to wait on new documents to satisfy a tailable cursor query. Requires `tailable` and `awaitData` to be true */ maxAwaitTimeMS?: number; @@ -78,6 +73,7 @@ export interface FindOptions * @deprecated This API is deprecated in favor of `collection.find().explain()`. */ explain?: ExplainOptions['explain']; + /** @internal*/ timeoutMode?: CursorTimeoutMode; } @@ -123,7 +119,7 @@ export class FindOperation extends CommandOperation { let findCommand = makeFindCommand(this.ns, this.filter, options); if (this.explain) { - validateExplainTimeoutOptions(this.options, this.explain); + cleanUpExplainTimeoutOptions(this.options, this.explain); findCommand = decorateWithExplain(findCommand, this.explain); } From 06dc385f29a868ecdbc9c734ae2b457feb66e475 Mon Sep 17 00:00:00 2001 From: Warren James Date: Tue, 22 Oct 2024 16:26:18 -0400 Subject: [PATCH 05/13] preserve write concern but overwrite wtimeoutms when timeoutMS is specified --- src/sessions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sessions.ts b/src/sessions.ts index de9c79072f9..8c9e3e3b201 100644 --- a/src/sessions.ts +++ b/src/sessions.ts @@ -499,7 +499,7 @@ export class ClientSession if (timeoutMS == null && this.timeoutContext == null) { WriteConcern.apply(command, { wtimeoutMS: 10000, w: 'majority', ...wc }); } else { - WriteConcern.apply(command, { w: 'majority', ...wc, wtimeoutMS: undefined }); + WriteConcern.apply(command, { ...wc, wtimeoutMS: undefined }); } } From 0d260e822e4bdf2dfbb94e77e5e2ab280daeb4e2 Mon Sep 17 00:00:00 2001 From: Warren James Date: Tue, 22 Oct 2024 17:20:48 -0400 Subject: [PATCH 06/13] more cleanly apply validation logic --- src/cursor/aggregation_cursor.ts | 14 +++++++++++--- src/cursor/find_cursor.ts | 15 ++++++++++++--- src/explain.ts | 10 ++++------ src/operations/command.ts | 6 +++--- src/operations/find.ts | 8 ++++++-- 5 files changed, 36 insertions(+), 17 deletions(-) diff --git a/src/cursor/aggregation_cursor.ts b/src/cursor/aggregation_cursor.ts index b42dc91ed5d..cace0a4b6a2 100644 --- a/src/cursor/aggregation_cursor.ts +++ b/src/cursor/aggregation_cursor.ts @@ -1,11 +1,11 @@ import type { Document } from '../bson'; import { MongoAPIError } from '../error'; import { - cleanUpExplainTimeoutOptions, Explain, ExplainableCursor, type ExplainCommandOptions, - type ExplainVerbosityLike + type ExplainVerbosityLike, + validateExplainTimeoutOptions } from '../explain'; import type { MongoClient } from '../mongo_client'; import { AggregateOperation, type AggregateOptions } from '../operations/aggregate'; @@ -75,7 +75,15 @@ export class AggregationCursor extends ExplainableCursor ...this.cursorOptions, session }; - cleanUpExplainTimeoutOptions(options, Explain.fromOptions(options)); + if (options.explain) { + try { + validateExplainTimeoutOptions(options, Explain.fromOptions(options)); + } catch { + throw new MongoAPIError( + 'timeoutMS cannot be used with explain when explain is specified in aggregateOptions' + ); + } + } const aggregateOperation = new AggregateOperation(this.namespace, this.pipeline, options); diff --git a/src/cursor/find_cursor.ts b/src/cursor/find_cursor.ts index 1763f1578bc..74df916633e 100644 --- a/src/cursor/find_cursor.ts +++ b/src/cursor/find_cursor.ts @@ -2,11 +2,11 @@ import { type Document } from '../bson'; import { CursorResponse } from '../cmap/wire_protocol/responses'; import { MongoAPIError, MongoInvalidArgumentError, MongoTailableCursorError } from '../error'; import { - cleanUpExplainTimeoutOptions, Explain, ExplainableCursor, type ExplainCommandOptions, - type ExplainVerbosityLike + type ExplainVerbosityLike, + validateExplainTimeoutOptions } from '../explain'; import type { MongoClient } from '../mongo_client'; import type { CollationOptions } from '../operations/command'; @@ -75,7 +75,16 @@ export class FindCursor extends ExplainableCursor { session }; - cleanUpExplainTimeoutOptions(options, Explain.fromOptions(options)); + const explain = Explain.fromOptions(options); + if (explain) { + try { + validateExplainTimeoutOptions(options, Explain.fromOptions(options)); + } catch { + throw new MongoAPIError( + 'timeoutMS cannot be used with explain when explain is specified in findOptions' + ); + } + } const findOperation = new FindOperation(this.namespace, this.cursorFilter, options); diff --git a/src/explain.ts b/src/explain.ts index 52a5e49a654..670bea53041 100644 --- a/src/explain.ts +++ b/src/explain.ts @@ -24,8 +24,7 @@ export type ExplainVerbosityLike = ExplainVerbosity | boolean; export interface ExplainCommandOptions { /** The explain verbosity for the command. */ verbosity: ExplainVerbosity; - /** The maxTimeMS setting for the command. - * @deprecated Will be removed in the next major version. Please use timeoutMS instead.*/ + /** The maxTimeMS setting for the command. */ maxTimeMS?: number; } @@ -66,7 +65,7 @@ export interface ExplainOptions { /** @internal */ export class Explain { readonly verbosity: ExplainVerbosity; - maxTimeMS?: number; + readonly maxTimeMS?: number; private constructor(verbosity: ExplainVerbosityLike, maxTimeMS?: number) { if (typeof verbosity === 'boolean') { @@ -92,11 +91,10 @@ export class Explain { } } -export function cleanUpExplainTimeoutOptions(options: Document, explain?: Explain) { +export function validateExplainTimeoutOptions(options: Document, explain?: Explain) { const { maxTimeMS, timeoutMS } = options; if (timeoutMS != null && (maxTimeMS != null || explain?.maxTimeMS != null)) { - if (maxTimeMS != null) delete options.maxTimeMS; - if (explain?.maxTimeMS != null) delete explain.maxTimeMS; + throw new MongoAPIError('Cannot use maxTimeMS with timeoutMS for explain commands.'); } } diff --git a/src/operations/command.ts b/src/operations/command.ts index 1ad5884eb1f..3114981ad3c 100644 --- a/src/operations/command.ts +++ b/src/operations/command.ts @@ -2,10 +2,10 @@ import type { BSONSerializeOptions, Document } from '../bson'; import { type MongoDBResponseConstructor } from '../cmap/wire_protocol/responses'; import { MongoInvalidArgumentError } from '../error'; import { - cleanUpExplainTimeoutOptions, decorateWithExplain, Explain, - type ExplainOptions + type ExplainOptions, + validateExplainTimeoutOptions } from '../explain'; import { ReadConcern } from '../read_concern'; import type { ReadPreference } from '../read_preference'; @@ -99,7 +99,7 @@ export abstract class CommandOperation extends AbstractOperation { if (this.hasAspect(Aspect.EXPLAINABLE)) { this.explain = Explain.fromOptions(options); - cleanUpExplainTimeoutOptions(this.options, this.explain); + if (this.explain) validateExplainTimeoutOptions(this.options, this.explain); } else if (options?.explain != null) { throw new MongoInvalidArgumentError(`Option "explain" is not supported on this command`); } diff --git a/src/operations/find.ts b/src/operations/find.ts index 833240e5161..1775ea6e07f 100644 --- a/src/operations/find.ts +++ b/src/operations/find.ts @@ -2,7 +2,11 @@ import type { Document } from '../bson'; import { CursorResponse, ExplainedCursorResponse } from '../cmap/wire_protocol/responses'; import { type AbstractCursorOptions, type CursorTimeoutMode } from '../cursor/abstract_cursor'; import { MongoInvalidArgumentError } from '../error'; -import { cleanUpExplainTimeoutOptions, decorateWithExplain, type ExplainOptions } from '../explain'; +import { + decorateWithExplain, + type ExplainOptions, + validateExplainTimeoutOptions +} from '../explain'; import { ReadConcern } from '../read_concern'; import type { Server } from '../sdam/server'; import type { ClientSession } from '../sessions'; @@ -119,7 +123,7 @@ export class FindOperation extends CommandOperation { let findCommand = makeFindCommand(this.ns, this.filter, options); if (this.explain) { - cleanUpExplainTimeoutOptions(this.options, this.explain); + validateExplainTimeoutOptions(this.options, this.explain); findCommand = decorateWithExplain(findCommand, this.explain); } From ac1991a17427bc33e97e76c5a9c8ed503d5359f6 Mon Sep 17 00:00:00 2001 From: Warren James Date: Tue, 22 Oct 2024 17:21:18 -0400 Subject: [PATCH 07/13] conditionally apply write concern --- src/sessions.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/sessions.ts b/src/sessions.ts index 8c9e3e3b201..7882434bf37 100644 --- a/src/sessions.ts +++ b/src/sessions.ts @@ -499,7 +499,10 @@ export class ClientSession if (timeoutMS == null && this.timeoutContext == null) { WriteConcern.apply(command, { wtimeoutMS: 10000, w: 'majority', ...wc }); } else { - WriteConcern.apply(command, { ...wc, wtimeoutMS: undefined }); + const wcKeys = Object.keys(wc); + if (wcKeys.length > 2 || (!wcKeys.includes('wtimeoutMS') && !wcKeys.includes('wTimeoutMS'))) + // if the write concern was specified with wTimeoutMS, then we set both wtimeoutMS and wTimeoutMS, guaranteeing at least two keys, so if we have more than two keys, then we can automatically assume that we should add the write concern to the command. If it has 2 or fewer keys, we need to check that those keys aren't the wtimeoutMS or wTimeoutMS options before we add the write concern to the command + WriteConcern.apply(command, { ...wc, wtimeoutMS: undefined }); } } From fbd9c431aab1fa8f9a4440780168cba945b06669 Mon Sep 17 00:00:00 2001 From: Warren James Date: Tue, 22 Oct 2024 17:26:38 -0400 Subject: [PATCH 08/13] clean up --- src/cursor/find_cursor.ts | 3 +-- src/sessions.ts | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/cursor/find_cursor.ts b/src/cursor/find_cursor.ts index 74df916633e..28cb373614d 100644 --- a/src/cursor/find_cursor.ts +++ b/src/cursor/find_cursor.ts @@ -75,8 +75,7 @@ export class FindCursor extends ExplainableCursor { session }; - const explain = Explain.fromOptions(options); - if (explain) { + if (options.explain) { try { validateExplainTimeoutOptions(options, Explain.fromOptions(options)); } catch { diff --git a/src/sessions.ts b/src/sessions.ts index 7882434bf37..9ada6124d5a 100644 --- a/src/sessions.ts +++ b/src/sessions.ts @@ -507,7 +507,6 @@ export class ClientSession } if (this.transaction.state === TxnState.TRANSACTION_COMMITTED || this.commitAttempted) { - WriteConcern.apply(command, { wtimeoutMS: 10000, ...wc, w: 'majority' }); if (timeoutMS == null && this.timeoutContext == null) { WriteConcern.apply(command, { wtimeoutMS: 10000, ...wc, w: 'majority' }); } else { From 616c44e7cd42fe9f22cb6216ee31ca25cdf27c8a Mon Sep 17 00:00:00 2001 From: Warren James Date: Wed, 23 Oct 2024 17:50:27 -0400 Subject: [PATCH 09/13] fix tsdoc comments --- src/cursor/abstract_cursor.ts | 6 ++++-- src/cursor/run_command_cursor.ts | 6 ++++-- src/mongo_client.ts | 6 ++++-- src/write_concern.ts | 3 ++- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/cursor/abstract_cursor.ts b/src/cursor/abstract_cursor.ts index dd3c40bfab6..f8f9a9ea097 100644 --- a/src/cursor/abstract_cursor.ts +++ b/src/cursor/abstract_cursor.ts @@ -84,7 +84,8 @@ export interface AbstractCursorOptions extends BSONSerializeOptions { /** * When applicable `maxTimeMS` controls the amount of time the initial command * that constructs a cursor should take. (ex. find, aggregate, listCollections) - * @deprecated Will be removed in the next major version. Please use timeoutMS instead. + * @deprecated + * Will be removed in the next major version. Please use timeoutMS instead. */ maxTimeMS?: number; /** @@ -722,7 +723,8 @@ export abstract class AbstractCursor< * Set a maxTimeMS on the cursor query, allowing for hard timeout limits on queries (Only supported on MongoDB 2.6 or higher) * * @param value - Number of milliseconds to wait before aborting the query. - * @deprecated Will be removed in the next major version. Please use the timeoutMS option instead. + * @deprecated + * Will be removed in the next major version. Please use the timeoutMS option instead. */ maxTimeMS(value: number): this { this.throwIfInitialized(); diff --git a/src/cursor/run_command_cursor.ts b/src/cursor/run_command_cursor.ts index 839b5890099..70001b0c0dc 100644 --- a/src/cursor/run_command_cursor.ts +++ b/src/cursor/run_command_cursor.ts @@ -48,7 +48,8 @@ export class RunCommandCursor extends AbstractCursor { /** * Controls the `getMore.maxTimeMS` field. Only valid when cursor is tailable await * @param maxTimeMS - the number of milliseconds to wait for new data - * @deprecated Will be removed in the next major version. Please use timeoutMS instead. + * @deprecated + * Will be removed in the next major version. Please use timeoutMS instead. */ public setMaxTimeMS(maxTimeMS: number): this { this.getMoreOptions.maxAwaitTimeMS = maxTimeMS; @@ -84,7 +85,8 @@ export class RunCommandCursor extends AbstractCursor { } /** Unsupported for RunCommandCursor: maxTimeMS must be configured directly on command document - * @deprecated Will be removed in the next major version. */ + * @deprecated + * Will be removed in the next major version. */ public override maxTimeMS(_: number): never { throw new MongoAPIError( 'maxTimeMS must be configured on the command document directly, to configure getMore.maxTimeMS use cursor.setMaxTimeMS()' diff --git a/src/mongo_client.ts b/src/mongo_client.ts index ad72cc4539b..95533351404 100644 --- a/src/mongo_client.ts +++ b/src/mongo_client.ts @@ -153,7 +153,8 @@ export interface MongoClientOptions extends BSONSerializeOptions, SupportedNodeC /** The time in milliseconds to attempt a connection before timing out. */ connectTimeoutMS?: number; /** The time in milliseconds to attempt a send or receive on a socket before the attempt times out. - * @deprecated Will be removed in the next major version. Please use timeoutMS instead */ + * @deprecated + * Will be removed in the next major version. Please use timeoutMS instead */ socketTimeoutMS?: number; /** An array or comma-delimited string of compressors to enable network compression for communication between this client and a mongod/mongos instance. */ compressors?: CompressorName[] | string; @@ -178,7 +179,8 @@ export interface MongoClientOptions extends BSONSerializeOptions, SupportedNodeC /** The maximum number of milliseconds that a connection can remain idle in the pool before being removed and closed. */ maxIdleTimeMS?: number; /** The maximum time in milliseconds that a thread can wait for a connection to become available. - * @deprecated Will be removed in the next major version. Please use timeoutMS instead */ + * @deprecated + * Will be removed in the next major version. Please use timeoutMS instead */ waitQueueTimeoutMS?: number; /** Specify a read concern for the collection (only MongoDB 3.2 or higher supported) */ readConcern?: ReadConcernLike; diff --git a/src/write_concern.ts b/src/write_concern.ts index 1406151c0d0..e1383006c18 100644 --- a/src/write_concern.ts +++ b/src/write_concern.ts @@ -29,7 +29,8 @@ export interface WriteConcernSettings { j?: boolean; /** * The write concern timeout. - * @deprecated Will be removed in the next major version. Please use the wtimeoutMS option. + * @deprecated + * Will be removed in the next major version. Please use the wtimeoutMS option. */ wtimeout?: number; /** From 2a267e88d4f3272aaea15a553d66554eca3292d0 Mon Sep 17 00:00:00 2001 From: Warren James Date: Wed, 23 Oct 2024 18:06:18 -0400 Subject: [PATCH 10/13] add type tests --- test/types/mongodb.test-d.ts | 24 ++++++++++++++++++++++++ test/types/write_concern.test-d.ts | 9 +++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/test/types/mongodb.test-d.ts b/test/types/mongodb.test-d.ts index 892235f4747..4e772d51a22 100644 --- a/test/types/mongodb.test-d.ts +++ b/test/types/mongodb.test-d.ts @@ -20,9 +20,33 @@ declare const options: MongoDBDriver.MongoClientOptions; expectDeprecated(options.w); expectDeprecated(options.journal); expectDeprecated(options.wtimeoutMS); +expectDeprecated(options.socketTimeoutMS); +expectDeprecated(options.waitQueueTimeoutMS); expectNotDeprecated(options.writeConcern); expectType(options.writeConcern); +declare const estimatedDocumentCountOptions: MongoDBDriver.EstimatedDocumentCountOptions; +expectDeprecated(estimatedDocumentCountOptions.maxTimeMS); + +declare const countOptions: MongoDBDriver.CountOptions; +expectDeprecated(countOptions.maxTimeMS); + +declare const commandOptions: MongoDBDriver.CommandOperationOptions; +expectDeprecated(commandOptions.maxTimeMS); + +declare const aggregateOptions: MongoDBDriver.AggregateOptions; +expectDeprecated(aggregateOptions.maxTimeMS); + +declare const runCommandCursor: MongoDBDriver.RunCommandCursor; +expectDeprecated(runCommandCursor.setMaxTimeMS); +expectDeprecated(runCommandCursor.maxTimeMS); + +declare const cursorOptions: MongoDBDriver.AbstractCursorOptions; +expectDeprecated(cursorOptions.maxTimeMS); + +declare const abstractCursor: MongoDBDriver.AbstractCursor; +expectDeprecated(abstractCursor.maxTimeMS); + interface TSchema extends Document { name: string; } diff --git a/test/types/write_concern.test-d.ts b/test/types/write_concern.test-d.ts index b4249de86c8..fefcaf4fc84 100644 --- a/test/types/write_concern.test-d.ts +++ b/test/types/write_concern.test-d.ts @@ -1,13 +1,18 @@ -import { expectNotAssignable } from 'tsd'; +import { expectDeprecated, expectNotAssignable } from 'tsd'; import type { ChangeStreamOptions, FindOptions, ListCollectionsOptions, - ListIndexesOptions + ListIndexesOptions, + WriteConcern } from '../mongodb'; expectNotAssignable({ writeConcern: { w: 0 } }); expectNotAssignable({ writeConcern: { w: 0 } }); expectNotAssignable({ writeConcern: { w: 0 } }); expectNotAssignable({ writeConcern: { w: 0 } }); + +declare const wc: WriteConcern; +expectDeprecated(wc.wtimeoutMS); +expectDeprecated(wc.wtimeout); From b72bb439a687243c654d80e40091abf113738fc2 Mon Sep 17 00:00:00 2001 From: Warren James Date: Wed, 23 Oct 2024 18:06:29 -0400 Subject: [PATCH 11/13] fix tsdoc comments --- src/operations/aggregate.ts | 3 ++- src/operations/command.ts | 3 ++- src/operations/estimated_document_count.ts | 3 ++- src/operations/get_more.ts | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/operations/aggregate.ts b/src/operations/aggregate.ts index 4f05e690bdb..2e8fbc6e7a0 100644 --- a/src/operations/aggregate.ts +++ b/src/operations/aggregate.ts @@ -27,7 +27,8 @@ export interface AggregateOptions extends Omit it returns as a real cursor on pre 2.6 it returns as an emulated cursor. */ cursor?: Document; /** specifies a cumulative time limit in milliseconds for processing operations on the cursor. MongoDB interrupts the operation at the earliest following interrupt point. - * @deprecated Will be removed in the next major version. Please use timeoutMS instead.*/ + * @deprecated + * Will be removed in the next major version. Please use timeoutMS instead.*/ maxTimeMS?: number; /** The maximum amount of time for the server to wait on new documents to satisfy a tailable cursor query. */ maxAwaitTimeMS?: number; diff --git a/src/operations/command.ts b/src/operations/command.ts index 3114981ad3c..bbce8ad7f65 100644 --- a/src/operations/command.ts +++ b/src/operations/command.ts @@ -41,7 +41,8 @@ export interface CommandOperationOptions /** Collation */ collation?: CollationOptions; /** - * @deprecated Will be removed in the next major version. Please use timeoutMS instead. */ + * @deprecated + * Will be removed in the next major version. Please use timeoutMS instead. */ maxTimeMS?: number; /** * Comment to apply to the operation. diff --git a/src/operations/estimated_document_count.ts b/src/operations/estimated_document_count.ts index 79b58fbfe88..f96ee8d5408 100644 --- a/src/operations/estimated_document_count.ts +++ b/src/operations/estimated_document_count.ts @@ -12,7 +12,8 @@ export interface EstimatedDocumentCountOptions extends CommandOperationOptions { * The maximum amount of time to allow the operation to run. * * This option is sent only if the caller explicitly provides a value. The default is to not send a value. - *@deprecated Will be removed in the next major version. Please use timeoutMS instead. + *@deprecated + Will be removed in the next major version. Please use timeoutMS instead. */ maxTimeMS?: number; } diff --git a/src/operations/get_more.ts b/src/operations/get_more.ts index d4bf84e7446..34317d533b5 100644 --- a/src/operations/get_more.ts +++ b/src/operations/get_more.ts @@ -17,7 +17,7 @@ export interface GetMoreOptions extends OperationOptions { * getMore only supports 'comment' in server versions 4.4 and above. */ comment?: unknown; - /** Number of milliseconds to wait before aborting the query. + /** Number of milliseconds to wait before aborting the query. */ maxTimeMS?: number; /** TODO(NODE-4413): Address bug with maxAwaitTimeMS not being passed in from the cursor correctly */ maxAwaitTimeMS?: number; From 34aca6d6fb75c1c2f483552ee532c311091c56d8 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Thu, 24 Oct 2024 14:18:09 -0400 Subject: [PATCH 12/13] chore: fix docs formatting --- src/cursor/abstract_cursor.ts | 6 ++---- src/cursor/run_command_cursor.ts | 10 +++++----- src/mongo_client.ts | 14 ++++++++------ src/operations/aggregate.ts | 7 ++++--- src/operations/command.ts | 5 +++-- src/operations/count.ts | 6 ++++-- src/operations/estimated_document_count.ts | 3 +-- src/write_concern.ts | 6 ++++-- 8 files changed, 31 insertions(+), 26 deletions(-) diff --git a/src/cursor/abstract_cursor.ts b/src/cursor/abstract_cursor.ts index f8f9a9ea097..dd3c40bfab6 100644 --- a/src/cursor/abstract_cursor.ts +++ b/src/cursor/abstract_cursor.ts @@ -84,8 +84,7 @@ export interface AbstractCursorOptions extends BSONSerializeOptions { /** * When applicable `maxTimeMS` controls the amount of time the initial command * that constructs a cursor should take. (ex. find, aggregate, listCollections) - * @deprecated - * Will be removed in the next major version. Please use timeoutMS instead. + * @deprecated Will be removed in the next major version. Please use timeoutMS instead. */ maxTimeMS?: number; /** @@ -723,8 +722,7 @@ export abstract class AbstractCursor< * Set a maxTimeMS on the cursor query, allowing for hard timeout limits on queries (Only supported on MongoDB 2.6 or higher) * * @param value - Number of milliseconds to wait before aborting the query. - * @deprecated - * Will be removed in the next major version. Please use the timeoutMS option instead. + * @deprecated Will be removed in the next major version. Please use the timeoutMS option instead. */ maxTimeMS(value: number): this { this.throwIfInitialized(); diff --git a/src/cursor/run_command_cursor.ts b/src/cursor/run_command_cursor.ts index 70001b0c0dc..15f95042c7f 100644 --- a/src/cursor/run_command_cursor.ts +++ b/src/cursor/run_command_cursor.ts @@ -48,8 +48,7 @@ export class RunCommandCursor extends AbstractCursor { /** * Controls the `getMore.maxTimeMS` field. Only valid when cursor is tailable await * @param maxTimeMS - the number of milliseconds to wait for new data - * @deprecated - * Will be removed in the next major version. Please use timeoutMS instead. + * @deprecated Will be removed in the next major version. Please use timeoutMS instead. */ public setMaxTimeMS(maxTimeMS: number): this { this.getMoreOptions.maxAwaitTimeMS = maxTimeMS; @@ -84,9 +83,10 @@ export class RunCommandCursor extends AbstractCursor { ); } - /** Unsupported for RunCommandCursor: maxTimeMS must be configured directly on command document - * @deprecated - * Will be removed in the next major version. */ + /** + * Unsupported for RunCommandCursor: maxTimeMS must be configured directly on command document + * @deprecated Will be removed in the next major version. + */ public override maxTimeMS(_: number): never { throw new MongoAPIError( 'maxTimeMS must be configured on the command document directly, to configure getMore.maxTimeMS use cursor.setMaxTimeMS()' diff --git a/src/mongo_client.ts b/src/mongo_client.ts index 95533351404..a332684b0ef 100644 --- a/src/mongo_client.ts +++ b/src/mongo_client.ts @@ -152,9 +152,10 @@ export interface MongoClientOptions extends BSONSerializeOptions, SupportedNodeC tlsInsecure?: boolean; /** The time in milliseconds to attempt a connection before timing out. */ connectTimeoutMS?: number; - /** The time in milliseconds to attempt a send or receive on a socket before the attempt times out. - * @deprecated - * Will be removed in the next major version. Please use timeoutMS instead */ + /** + * The time in milliseconds to attempt a send or receive on a socket before the attempt times out. + * @deprecated Will be removed in the next major version. Please use timeoutMS instead + */ socketTimeoutMS?: number; /** An array or comma-delimited string of compressors to enable network compression for communication between this client and a mongod/mongos instance. */ compressors?: CompressorName[] | string; @@ -178,9 +179,10 @@ export interface MongoClientOptions extends BSONSerializeOptions, SupportedNodeC maxConnecting?: number; /** The maximum number of milliseconds that a connection can remain idle in the pool before being removed and closed. */ maxIdleTimeMS?: number; - /** The maximum time in milliseconds that a thread can wait for a connection to become available. - * @deprecated - * Will be removed in the next major version. Please use timeoutMS instead */ + /** + * The maximum time in milliseconds that a thread can wait for a connection to become available. + * @deprecated Will be removed in the next major version. Please use timeoutMS instead + */ waitQueueTimeoutMS?: number; /** Specify a read concern for the collection (only MongoDB 3.2 or higher supported) */ readConcern?: ReadConcernLike; diff --git a/src/operations/aggregate.ts b/src/operations/aggregate.ts index 2e8fbc6e7a0..3407e64cebb 100644 --- a/src/operations/aggregate.ts +++ b/src/operations/aggregate.ts @@ -26,9 +26,10 @@ export interface AggregateOptions extends Omit it returns as a real cursor on pre 2.6 it returns as an emulated cursor. */ cursor?: Document; - /** specifies a cumulative time limit in milliseconds for processing operations on the cursor. MongoDB interrupts the operation at the earliest following interrupt point. - * @deprecated - * Will be removed in the next major version. Please use timeoutMS instead.*/ + /** + * Specifies a cumulative time limit in milliseconds for processing operations on the cursor. MongoDB interrupts the operation at the earliest following interrupt point. + * @deprecated Will be removed in the next major version. Please use timeoutMS instead. + */ maxTimeMS?: number; /** The maximum amount of time for the server to wait on new documents to satisfy a tailable cursor query. */ maxAwaitTimeMS?: number; diff --git a/src/operations/command.ts b/src/operations/command.ts index bbce8ad7f65..13412e7cd70 100644 --- a/src/operations/command.ts +++ b/src/operations/command.ts @@ -41,8 +41,9 @@ export interface CommandOperationOptions /** Collation */ collation?: CollationOptions; /** - * @deprecated - * Will be removed in the next major version. Please use timeoutMS instead. */ + * maxTimeMS is a server-side time limit in milliseconds for processing an operation. + * @deprecated Will be removed in the next major version. Please use timeoutMS instead. + */ maxTimeMS?: number; /** * Comment to apply to the operation. diff --git a/src/operations/count.ts b/src/operations/count.ts index da79a20e835..1f8f96aef27 100644 --- a/src/operations/count.ts +++ b/src/operations/count.ts @@ -13,8 +13,10 @@ export interface CountOptions extends CommandOperationOptions { skip?: number; /** The maximum amounts to count before aborting. */ limit?: number; - /** Number of milliseconds to wait before aborting the query. - * @deprecated Will be removed in the next major version. Please use timeoutMS instead. */ + /** + * Number of milliseconds to wait before aborting the query. + * @deprecated Will be removed in the next major version. Please use timeoutMS instead. + */ maxTimeMS?: number; /** An index name hint for the query. */ hint?: string | Document; diff --git a/src/operations/estimated_document_count.ts b/src/operations/estimated_document_count.ts index f96ee8d5408..68df4b002e2 100644 --- a/src/operations/estimated_document_count.ts +++ b/src/operations/estimated_document_count.ts @@ -12,8 +12,7 @@ export interface EstimatedDocumentCountOptions extends CommandOperationOptions { * The maximum amount of time to allow the operation to run. * * This option is sent only if the caller explicitly provides a value. The default is to not send a value. - *@deprecated - Will be removed in the next major version. Please use timeoutMS instead. + * @deprecated Will be removed in the next major version. Please use timeoutMS instead. */ maxTimeMS?: number; } diff --git a/src/write_concern.ts b/src/write_concern.ts index e1383006c18..bf88aa6a74f 100644 --- a/src/write_concern.ts +++ b/src/write_concern.ts @@ -67,8 +67,10 @@ export class WriteConcern { readonly w?: W; /** Request acknowledgment that the write operation has been written to the on-disk journal */ readonly journal?: boolean; - /** Specify a time limit to prevent write operations from blocking indefinitely - * @deprecated Will be removed in the next major version. Please use timeoutMS */ + /** + * Specify a time limit to prevent write operations from blocking indefinitely. + * @deprecated Will be removed in the next major version. Please use timeoutMS + */ readonly wtimeoutMS?: number; /** * Specify a time limit to prevent write operations from blocking indefinitely. From 5267dd7c30db85f604f211b96cbd4fa860556bce Mon Sep 17 00:00:00 2001 From: Warren James Date: Thu, 24 Oct 2024 16:35:30 -0400 Subject: [PATCH 13/13] update deprecation tests --- test/types/mongodb.test-d.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/types/mongodb.test-d.ts b/test/types/mongodb.test-d.ts index 4e772d51a22..c87933514f2 100644 --- a/test/types/mongodb.test-d.ts +++ b/test/types/mongodb.test-d.ts @@ -23,6 +23,9 @@ expectDeprecated(options.wtimeoutMS); expectDeprecated(options.socketTimeoutMS); expectDeprecated(options.waitQueueTimeoutMS); expectNotDeprecated(options.writeConcern); +expectNotDeprecated(options.serverSelectionTimeoutMS); +expectNotDeprecated(options.connectTimeoutMS); + expectType(options.writeConcern); declare const estimatedDocumentCountOptions: MongoDBDriver.EstimatedDocumentCountOptions; @@ -47,6 +50,9 @@ expectDeprecated(cursorOptions.maxTimeMS); declare const abstractCursor: MongoDBDriver.AbstractCursor; expectDeprecated(abstractCursor.maxTimeMS); +declare const txnOptions: MongoDBDriver.TransactionOptions; +expectDeprecated(txnOptions.maxCommitTimeMS); + interface TSchema extends Document { name: string; }