Skip to content

Commit 705cab0

Browse files
use for loop
1 parent dba19cd commit 705cab0

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/cursor/abstract_cursor.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ export abstract class AbstractCursor<
686686
async toArray(): Promise<TSchema[]> {
687687
this.signal?.throwIfAborted();
688688

689-
let array: TSchema[] = [];
689+
const array: TSchema[] = [];
690690
// at the end of the loop (since readBufferedDocuments is called) the buffer will be empty
691691
// then, the 'await of' syntax will run a getMore call
692692
for await (const document of this) {
@@ -699,7 +699,9 @@ export abstract class AbstractCursor<
699699
} else {
700700
// Note: previous versions of this logic used `array.push(...)`, which adds each item
701701
// to the callstack. For large arrays, this can exceed the maximum call size.
702-
array = array.concat(docs);
702+
for (const doc of docs) {
703+
array.push(doc);
704+
}
703705
}
704706
}
705707
return array;

0 commit comments

Comments
 (0)