forEach()

Iterates over all values in a Set, executes a function with each value, and returns nothing.

Signature

forEach(lambda: (value: T) => any): null

Description

forEach() iterates over all values in the Set, executes the provided lambda function with each value, and returns nothing. It is used for mutations or writing documents based on each Set value.

Because this method scans the full set, the query can time out for large sets.

Parameters

Parameter Type Required Description

lambda

Function

Yes

Anonymous Function that operates on a Set value and returns nothing.

lambda parameters:

Parameter Type Required Description

value

Any

Yes

Value to process.

Return value

Type Description None

Examples

Update all Customers documents where the first name is Carol and the last name is Clark, to change the phone number to 1-555-555-1212:

Customer
  .all()
  .where(.firstName == 'Carol' && .lastName == 'Clark')
  .forEach(
    customer => customer.update({ telephone: '1-555-555-1212' })
  )
null

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!