Skip to content

Commit c51d47e

Browse files
committed
fix: make findOne() close implicit session to avoid memory leak
1 parent 2ab2189 commit c51d47e

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/collection.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,10 @@ export class Collection<TSchema extends Document = Document> {
493493
filter: Filter<TSchema> = {},
494494
options: FindOptions = {}
495495
): Promise<WithId<TSchema> | null> {
496-
return this.find(filter, options).limit(-1).batchSize(1).next();
496+
const cursor = this.find(filter, options).limit(-1).batchSize(1);
497+
const res = await cursor.next();
498+
await cursor.close();
499+
return res;
497500
}
498501

499502
/**

0 commit comments

Comments
 (0)