Database Reference
In-Depth Information
There is another way of writing cypher queries where we can combine multiple statements
into one single statement. Extending the preceding example, we can combine all three
CREATE
statements into one single
CREATE
statement and add a
RETURN
in the end to
see the actual value of nodes and relationships persisted in the Neo4j database:
CREATE (actor:Actor {Name: "Russell Crowe", Age:
50})-[r:ACTED_IN{Language:"English"}]->(movie:Movie {Title:
"NOAH", Year:2014}) return actor,r,movie;
We can also capture the pattern defined in the preceding statement in a variable and then
return the variable to the invoking program:
CREATE p = (:Actor {Name: "Russell Crowe", Age:
50})-[:ACTED_IN{LANGUAGE:"English"}]->(:Movie {Title:
"NOAH",
Year:2014})<-[:DIRECTED{LANGUAGE:"English"}]-(:Actor {Name:
"Darren Aronofsky", Age: 45})
return p;
Capturing patterns in a variable also helps in situations where all parts of patterns are not
already in the scope of a single
CREATE
or
MATCH
. For example, in the preceding query,