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

Function forEach

src/cursor/abstract_cursor.ts:627–639  ·  view source on GitHub ↗

* Iterates over all the documents for this cursor using the iterator, callback pattern. * * If the iterator returns `false`, iteration will stop. * * @param iterator - The iteration callback. * @deprecated - Will be removed in a future release. Use for await...of instead.

(iterator: (doc: TSchema) => boolean | void)

Source from the content-addressed store, hash-verified

625 * @deprecated - Will be removed in a future release. Use for await...of instead.
626 */
627 async forEach(iterator: (doc: TSchema) => boolean | void): Promise<void> {
628 this.signal?.throwIfAborted();
629
630 if (typeof iterator !== 'function') {
631 throw new MongoInvalidArgumentError('Argument "iterator" must be a function');
632 }
633 for await (const document of this) {
634 const result = iterator(document);
635 if (result === false) {
636 break;
637 }
638 }
639 }
640
641 /**
642 * Frees any client-side resources used by the cursor.

Callers

nothing calls this directly

Calls 2

iteratorFunction · 0.85
throwIfAbortedMethod · 0.80

Tested by

no test coverage detected