Get the next available document from the cursor, returns null if no more documents are available.
()
| 552 | |
| 553 | /** Get the next available document from the cursor, returns null if no more documents are available. */ |
| 554 | async next(): Promise<TSchema | null> { |
| 555 | this.signal?.throwIfAborted(); |
| 556 | |
| 557 | if (this.cursorId === Long.ZERO) { |
| 558 | throw new MongoCursorExhaustedError(); |
| 559 | } |
| 560 | |
| 561 | if (this.cursorOptions.timeoutMode === CursorTimeoutMode.ITERATION && this.cursorId != null) { |
| 562 | this.timeoutContext?.refresh(); |
| 563 | } |
| 564 | |
| 565 | try { |
| 566 | do { |
| 567 | const doc = this.documents?.shift(this.deserializationOptions); |
| 568 | if (doc != null) { |
| 569 | if (this.transform != null) return await this.transformDocument(doc); |
| 570 | return doc; |
| 571 | } |
| 572 | await this.fetchBatch(); |
| 573 | } while (!this.isDead || (this.documents?.length ?? 0) !== 0); |
| 574 | } finally { |
| 575 | if (this.cursorOptions.timeoutMode === CursorTimeoutMode.ITERATION) { |
| 576 | this.timeoutContext?.clear(); |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | return null; |
| 581 | } |
| 582 | |
| 583 | /** |
| 584 | * Try to get the next available document from the cursor or `null` if an empty batch is returned |
nothing calls this directly
no test coverage detected