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

Method next

src/change_stream.ts:747–779  ·  view source on GitHub ↗

Get the next available document from the Change Stream.

()

Source from the content-addressed store, hash-verified

745
746 /** Get the next available document from the Change Stream. */
747 async next(): Promise<TChange> {
748 this._setIsIterator();
749 // Change streams must resume indefinitely while each resume event succeeds.
750 // This loop continues until either a change event is received or until a resume attempt
751 // fails.
752 this.timeoutContext?.refresh();
753
754 try {
755 while (true) {
756 try {
757 const change = await this.cursor.next();
758 const processedChange = this._processChange(change ?? null);
759 return processedChange;
760 } catch (error) {
761 try {
762 await this._processErrorIteratorMode(error, this.cursor.id != null);
763 } catch (error) {
764 if (error instanceof MongoOperationTimeoutError && this.cursor.id == null) {
765 throw error;
766 }
767 try {
768 await this.close();
769 } catch (error) {
770 squashError(error);
771 }
772 throw error;
773 }
774 }
775 }
776 } finally {
777 this.timeoutContext?.clear();
778 }
779 }
780
781 /**
782 * Try to get the next available document from the Change Stream's cursor or `null` if an empty batch is returned

Callers 15

findOneMethod · 0.45
countDocumentsMethod · 0.45
doReadFunction · 0.45
createConnectionMethod · 0.45
[Symbol.asyncIterator]Function · 0.45
_readNextMethod · 0.45
main.jsFile · 0.45
main.jsFile · 0.45
main.jsFile · 0.45
main.jsFile · 0.45
main.jsFile · 0.45

Calls 7

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

Tested by

no test coverage detected