diff --git a/src/collection.ts b/src/collection.ts index a73a5276f5f..62fa5bd4cba 100644 --- a/src/collection.ts +++ b/src/collection.ts @@ -501,12 +501,18 @@ export class Collection { */ async findOne(): Promise | null>; async findOne(filter: Filter): Promise | null>; - async findOne(filter: Filter, options: FindOptions): Promise | null>; + async findOne( + filter: Filter, + options: Omit + ): Promise | null>; // allow an override of the schema. async findOne(): Promise; async findOne(filter: Filter): Promise; - async findOne(filter: Filter, options?: FindOptions): Promise; + async findOne( + filter: Filter, + options?: Omit + ): Promise; async findOne( filter: Filter = {}, diff --git a/src/gridfs/download.ts b/src/gridfs/download.ts index f4b1f8450b2..19651b885ea 100644 --- a/src/gridfs/download.ts +++ b/src/gridfs/download.ts @@ -401,8 +401,7 @@ function init(stream: GridFSBucketReadStream): void { `Download timed out after ${stream.s.timeoutContext?.timeoutMS}ms` ); } catch (error) { - if (!stream.destroyed) - stream.destroy(error); + if (!stream.destroyed) stream.destroy(error); return; } diff --git a/src/gridfs/index.ts b/src/gridfs/index.ts index 21306a935d5..69ab95d061e 100644 --- a/src/gridfs/index.ts +++ b/src/gridfs/index.ts @@ -7,6 +7,7 @@ import { type Filter, TypedEventEmitter } from '../mongo_types'; import type { ReadPreference } from '../read_preference'; import type { Sort } from '../sort'; import { CSOTTimeoutContext } from '../timeout'; +import { resolveOptions } from '../utils'; import { WriteConcern, type WriteConcernOptions } from '../write_concern'; import type { FindOptions } from './../operations/find'; import { @@ -155,7 +156,7 @@ export class GridFSBucket extends TypedEventEmitter { * @param id - The id of the file doc */ async delete(id: ObjectId, options?: { timeoutMS: number }): Promise { - const timeoutMS = options?.timeoutMS ?? this.s.db.timeoutMS; + const { timeoutMS } = resolveOptions(this.s.db, options); let timeoutContext: CSOTTimeoutContext | undefined = undefined; if (timeoutMS) { @@ -235,7 +236,7 @@ export class GridFSBucket extends TypedEventEmitter { /** Removes this bucket's files collection, followed by its chunks collection. */ async drop(options?: { timeoutMS: number }): Promise { - const timeoutMS = options?.timeoutMS ?? this.s.db.timeoutMS; + const { timeoutMS } = resolveOptions(this.s.db, options); let timeoutContext: CSOTTimeoutContext | undefined = undefined; if (timeoutMS) { diff --git a/src/gridfs/upload.ts b/src/gridfs/upload.ts index 9a499799db4..c7544b715d8 100644 --- a/src/gridfs/upload.ts +++ b/src/gridfs/upload.ts @@ -345,8 +345,7 @@ async function checkIndexes(stream: GridFSBucketWriteStream): Promise { {}, { projection: { _id: 1 }, - timeoutMS: remainingTimeMS, - timeoutMode: remainingTimeMS != null ? CursorTimeoutMode.LIFETIME : undefined + timeoutMS: remainingTimeMS } ); if (doc != null) {