|
1 | | -import { DEFAULT_PK_FACTORY, emitWarningOnce, resolveOptions } from './utils'; |
| 1 | +import { DEFAULT_PK_FACTORY, emitWarningOnce, maybePromise, resolveOptions } from './utils'; |
2 | 2 | import { ReadPreference, ReadPreferenceLike } from './read_preference'; |
3 | 3 | import { |
4 | 4 | normalizeHintField, |
@@ -40,7 +40,6 @@ import { |
40 | 40 | EstimatedDocumentCountOptions |
41 | 41 | } from './operations/estimated_document_count'; |
42 | 42 | import type { FindOptions } from './operations/find'; |
43 | | -import { FindOneOperation } from './operations/find_one'; |
44 | 43 | import { |
45 | 44 | FindOneAndDeleteOperation, |
46 | 45 | FindOneAndReplaceOperation, |
@@ -709,16 +708,13 @@ export class Collection<TSchema extends Document = Document> { |
709 | 708 | (callback = filter as Callback<Document | undefined>), (filter = {}), (options = {}); |
710 | 709 | if (typeof options === 'function') (callback = options), (options = {}); |
711 | 710 |
|
712 | | - filter ??= {}; |
713 | | - |
714 | | - return executeOperation( |
715 | | - getTopology(this), |
716 | | - new FindOneOperation( |
717 | | - this as TODO_NODE_3286, |
718 | | - filter, |
719 | | - resolveOptions(this, options) |
720 | | - ) as TODO_NODE_3286, |
721 | | - callback as TODO_NODE_3286 |
| 711 | + const finalFilter = filter ?? {}; |
| 712 | + const finalOptions = options ?? {}; |
| 713 | + return maybePromise(callback, callback => |
| 714 | + this.find(finalFilter, finalOptions) |
| 715 | + .limit(-1) |
| 716 | + .batchSize(1) |
| 717 | + .next((error, result) => callback(error, result ?? undefined)) |
722 | 718 | ); |
723 | 719 | } |
724 | 720 |
|
|
0 commit comments