| 540 | ): Promise<T | null>; |
| 541 | |
| 542 | async findOne( |
| 543 | filter: Filter<TSchema> = {}, |
| 544 | options: Omit<FindOneOptions, 'timeoutMode'> & Abortable = {} |
| 545 | ): Promise<WithId<TSchema> | null> { |
| 546 | // Explicitly set the limit to 1 and singleBatch to true for all commands, per the spec. |
| 547 | // noCursorTimeout must be unset as well as batchSize. |
| 548 | // See: https://github.com/mongodb/specifications/blob/master/source/crud/crud.md#findone-api-details |
| 549 | const { ...opts } = options; |
| 550 | opts.singleBatch = true; |
| 551 | const cursor = this.find(filter, opts).limit(1); |
| 552 | const result = await cursor.next(); |
| 553 | await cursor.close(); |
| 554 | return result; |
| 555 | } |
| 556 | |
| 557 | /** |
| 558 | * Creates a cursor for a filter that can be used to iterate over results from MongoDB |