I'm using Neo4j Desktop to develop the cypher queries I will need for my use case.
Suppose that my graph may or may not be seeded with data based on the following query.
CREATE (parent:Entity {id: 'Dan'})
CREATE (child:Component {id: 'Bob', value: 'aaa'})
CREATE (child)-[:CHILD_OF]->(parent)
RETURN parent, child
and then run this query.
MERGE (parent:Entity {id: 'Dan'})
MERGE (child:Component {id: 'Bob', value: 'bbb'})
MERGE (child)-[:CHILD_OF]->(parent)
RETURN parent, child
When this query is run I don't know whether the parent entity 'Dan' exists or not, nor do I know whether the child or relationship exists.
What I need is a query which creates the parent, child, and relationship if they don't exist. If they do exist, then all it should do is update the value of the child.
But this query ends up creating a new child so that the result is that after running this query, the parent has two children, one with the old value and one with the new value.
I don't think I can use MATCH because that presumes the nodes exist.