MCPcopy
hub / github.com/mongodb/node-mongodb-native / next

Function next

src/cursor/abstract_cursor.ts:554–581  ·  view source on GitHub ↗

Get the next available document from the cursor, returns null if no more documents are available.

()

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 4

throwIfAbortedMethod · 0.80
refreshMethod · 0.45
shiftMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected