Database Reference
In-Depth Information
The preceding statement will first try to match the given node. If the match is successful,
then it will ignore
ON CREATE
and execute the pattern defined in
ON MATCH
and will
create another property by name of
last_seen
and associate it with the provided node,
as shown in the following screenshot:
MERGE
can also be used with relationships where it checks whether a relationship exists,
and if not, then it creates a new one:
MATCH (actor:Actor {Name: "Russell Crowe", Age: 50}),
(movies:Movie {Title: "NOAH", Year: 2014})
MERGE (actor)-[r:ACTED_IN{Language:"English"}]->(movies)
return actor,r,movies;
The preceding statement has three parts. In the first statement, it defines the
MATCH
clause and instructs to match the existence of the given nodes. In the second statement, it
defines the
MERGE
statement and instructs either to create a new relationship, or if it
matches, then return the existing one. Finally, in the last statement, we used
return
actor,r,movies
and printed everything on the console.