The FOREACH clause is used to replace records within a listing whether components of a course, or end result of aggregation.
Syntax
Following is the syntax of the FOREACH clause.
MATCH p = (start node)-[*]->(end node)
WHERE start.node = "node_name" AND end.node = "node_name"
FOREACH (n IN nodes(p)| SET n.marked = TRUE)
FOREACH (n IN nodes(p)proceeding with the example, create a path p in Neo4j database as shown beneath.
CREATE p = (Dhawan {name:"Shikar Dhawan"})-[:TOPSCORRER_OF]->(Ind{name:
"India"})-[:WINNER_OF]->(CT2013{name: "Champions Trophy 2013"})
RETURN p
Following is a pattern Cypher Query which provides a belongings to all the nodes along the direction using the FOREACH clause.
MATCH p = (Dhawan)-[*]->(CT2013)
WHERE Dhawan.name = "Shikar Dhawan" AND CT2013.name = "Champions Trophy 2013"
FOREACH (n IN nodes(p)| SET n.marked = TRUE)
FOREACH (n IN nodes(p)query, perform the subsequent steps −
Step 1 − Open the Neo4j computer App and begin the Neo4j Server. Open the built-in browser app of Neo4j using the URL http://localhost:7474/ as shown within the following screenshot.
Step 2 − Copy and paste the desired query in the dollar set off and press the play button (to execute the query) highlighted inside the following screenshot.
Result
On executing, you'll get the following end result.
Verification
To verify the advent of the node, kind and execute the subsequent question in the dollar spark off.
MATCH (n) RETURN n
This query returns all the nodes in the database (we are able to discuss this question in detail within the coming chapters).
On executing, this question indicates the created node as shown within the following screenshot.