Question

Is there any way in cypher where one can detect if the relationship been created is new?

I am using merge to create a relationship if it doesn't exist. If the relationship created is new then I want to set the value of that relationship to be 0 (relationship.value), or else if the relationship already exists while querying, then I want to increment its existing value.

Please help

Was it helpful?

Solution

MERGE allows the optional usage of ON CREATE and ON MATCH:

MATCH (a:Label {prop:'value1'}), (b:Label {prop:'value2'})
MERGE (a)-[r:relType]->(b)
ON CREATE SET r.myValue = 0
ON MATCH SET r.myValue = r.myValue + 1
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top