File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -297,6 +297,7 @@ export abstract class AbstractCursor<
297
297
298
298
return bufferedDocs ;
299
299
}
300
+
300
301
async * [ Symbol . asyncIterator ] ( ) : AsyncGenerator < TSchema , void , void > {
301
302
if ( this . isClosed ) {
302
303
return ;
@@ -457,9 +458,24 @@ export abstract class AbstractCursor<
457
458
* cursor.rewind() can be used to reset the cursor.
458
459
*/
459
460
async toArray ( ) : Promise < TSchema [ ] > {
460
- const array = [ ] ;
461
+ const array : TSchema [ ] = [ ] ;
462
+
463
+ // when each loop iteration ends,documents will be empty and a 'await (const document of this)' will run a getMore operation
461
464
for await ( const document of this ) {
462
465
array . push ( document ) ;
466
+ let docs = this . readBufferedDocuments ( ) ;
467
+ if ( this . transform != null ) {
468
+ docs = await Promise . all (
469
+ docs . map ( async doc => {
470
+ if ( doc != null ) {
471
+ return await this . transformDocument ( doc ) ;
472
+ } else {
473
+ throw Error ;
474
+ }
475
+ } )
476
+ ) ;
477
+ }
478
+ array . push ( ...docs ) ;
463
479
}
464
480
return array ;
465
481
}
You can’t perform that action at this time.
0 commit comments