FOREACHclause is used to update data within a collection whether components of a path, or result of aggregation.
Lists and paths are key concepts in Cypher®.
FOREACH clause can be used to update data, such as executing update commands on elements in a path, or on a list created by aggregation.
The variable context within the
FOREACH parenthesis is separate from the one outside it.
This means that if you
CREATE a node variable within a
FOREACH, you will not be able to use it outside of the foreach statement, unless you match to find it.
FOREACH parentheses, you can do any of the updating commands —
If you want to execute an additional
Mark all nodes along a path
This query will set the property
true on all nodes along a path.
MATCH p=(start)-[*]->(finish) WHERE start.name = 'A' AND finish.name = 'D' FOREACH (n IN nodes(p) | SET n.marked = true)
Was this page helpful?