Skip to content

Commit 12eec9a

Browse files
authored
refactor(NODE-3519): remove force unpinning and simplify findOne (#2929)
1 parent e588d21 commit 12eec9a

File tree

3 files changed

+10
-57
lines changed

3 files changed

+10
-57
lines changed

src/collection.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DEFAULT_PK_FACTORY, emitWarningOnce, resolveOptions } from './utils';
1+
import { DEFAULT_PK_FACTORY, emitWarningOnce, maybePromise, resolveOptions } from './utils';
22
import { ReadPreference, ReadPreferenceLike } from './read_preference';
33
import {
44
normalizeHintField,
@@ -40,7 +40,6 @@ import {
4040
EstimatedDocumentCountOptions
4141
} from './operations/estimated_document_count';
4242
import type { FindOptions } from './operations/find';
43-
import { FindOneOperation } from './operations/find_one';
4443
import {
4544
FindOneAndDeleteOperation,
4645
FindOneAndReplaceOperation,
@@ -709,16 +708,13 @@ export class Collection<TSchema extends Document = Document> {
709708
(callback = filter as Callback<Document | undefined>), (filter = {}), (options = {});
710709
if (typeof options === 'function') (callback = options), (options = {});
711710

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))
722718
);
723719
}
724720

src/cursor/abstract_cursor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ function cleanupCursor(
769769
}
770770

771771
if (!session.inTransaction()) {
772-
maybeClearPinnedConnection(session, { error, force: true });
772+
maybeClearPinnedConnection(session, { error });
773773
}
774774
}
775775

@@ -786,7 +786,7 @@ function cleanupCursor(
786786
}
787787

788788
if (!session.inTransaction()) {
789-
maybeClearPinnedConnection(session, { error, force: true });
789+
maybeClearPinnedConnection(session, { error });
790790
}
791791
}
792792

src/operations/find_one.ts

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)