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

Function tryNext

src/cursor/abstract_cursor.ts:586–617  ·  view source on GitHub ↗

* Try to get the next available document from the cursor or `null` if an empty batch is returned

()

Source from the content-addressed store, hash-verified

584 * Try to get the next available document from the cursor or `null` if an empty batch is returned
585 */
586 async tryNext(): Promise<TSchema | null> {
587 this.signal?.throwIfAborted();
588
589 if (this.cursorId === Long.ZERO) {
590 throw new MongoCursorExhaustedError();
591 }
592
593 if (this.cursorOptions.timeoutMode === CursorTimeoutMode.ITERATION && this.cursorId != null) {
594 this.timeoutContext?.refresh();
595 }
596 try {
597 let doc = this.documents?.shift(this.deserializationOptions);
598 if (doc != null) {
599 if (this.transform != null) return await this.transformDocument(doc);
600 return doc;
601 }
602
603 await this.fetchBatch();
604
605 doc = this.documents?.shift(this.deserializationOptions);
606 if (doc != null) {
607 if (this.transform != null) return await this.transformDocument(doc);
608 return doc;
609 }
610 } finally {
611 if (this.cursorOptions.timeoutMode === CursorTimeoutMode.ITERATION) {
612 this.timeoutContext?.clear();
613 }
614 }
615
616 return null;
617 }
618
619 /**
620 * Iterates over all the documents for this cursor using the iterator, callback pattern.

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