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.
The identifier context inside of the foreach parenthesis is separate from the one outside it.
This means that if you CREATE
a node identifier inside of a FOREACH
, you will not be able to use it outside of the foreach statement, unless you match to find it.
Inside of the FOREACH
parentheses, you can do any of the updating commands — CREATE
, CREATE UNIQUE
, DELETE
, and FOREACH
.
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, but four properties are set.
Try this query live. (1) {"name":"D"} (2) {"name":"A"} (3) {"name":"B"} (4) {"name":"C"} (2)-[:KNOWS]->(3) {} (3)-[:KNOWS]->(4) {} (4)-[:KNOWS]->(1) {} start begin = node(2), end = node(1) match p = begin -[*]-> end foreach(n in nodes(p) : set n.marked = true)
Copyright © 2013 Neo Technology