I'm trying to build a Cypher query which will connect an actor to the movie, or update existing relationship with new values of relationship property. I'm thinking of something like this:
MATCH (actor:Person{name:"Tom Hanks"})
MATCH (movie:Movie{title:"Cloud Atlas"})
OPTIONAL MATCH (actor)-[r:ACTED_IN]->(movie)
SET r.roles = ['Role 1', 'Role 2']
This works fine for the actors and movies which came from the example in Neo4j and are already connected, but not when I try to create new relationship, because r
is null and cannot be updated.
So, how can I update r.roles
if the relationship r
exists or create a new relationship if it doesn't?