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

Method hasNext

src/change_stream.ts:713–744  ·  view source on GitHub ↗

Check if there is any document still available in the Change Stream

()

Source from the content-addressed store, hash-verified

711
712 /** Check if there is any document still available in the Change Stream */
713 async hasNext(): Promise<boolean> {
714 this._setIsIterator();
715 // Change streams must resume indefinitely while each resume event succeeds.
716 // This loop continues until either a change event is received or until a resume attempt
717 // fails.
718
719 this.timeoutContext?.refresh();
720 try {
721 while (true) {
722 try {
723 const hasNext = await this.cursor.hasNext();
724 return hasNext;
725 } catch (error) {
726 try {
727 await this._processErrorIteratorMode(error, this.cursor.id != null);
728 } catch (error) {
729 if (error instanceof MongoOperationTimeoutError && this.cursor.id == null) {
730 throw error;
731 }
732 try {
733 await this.close();
734 } catch (error) {
735 squashError(error);
736 }
737 throw error;
738 }
739 }
740 }
741 } finally {
742 this.timeoutContext?.clear();
743 }
744 }
745
746 /** Get the next available document from the Change Stream. */
747 async next(): Promise<TChange> {

Callers 10

operations.tsFile · 0.80
testFunction · 0.80

Calls 6

_setIsIteratorMethod · 0.95
closeMethod · 0.95
squashErrorFunction · 0.90
refreshMethod · 0.45
clearMethod · 0.45

Tested by 1

testFunction · 0.64