简体   繁体   中英

Handling null values in Cypher, Neo4j

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM