16.21. Foreach

16.21.1. Mark all nodes along a path

Collections and paths are key concepts in Cypher. To use them for updating data, you can use the FOREACH construct. It allows you to do updating commands on elements in a collection - a path, or a collection created by aggregation.

16.21.1. Mark all nodes along a path

This query will set the property marked to true on all nodes along a path.

Query

START begin = node(2), end = node(1)
MATCH p = begin -[*]-> end foreach(n in nodes(p) :
SET n.marked = true)

Nothing is returned from this query

Result

Properties set: 4
3 ms

(empty result)