Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Neo4j create if not exist otherwise update

Tags:

neo4j

I need to create a relation between two users once, and update its properties since then. Is there a way to do something like "create if not exist otherwise update" in Neo4j using Cypher?

like image 414
HanXu Avatar asked Mar 20 '23 13:03

HanXu


1 Answers

MERGE (u1:User)-[r:REL]->(u2:User)
ON CREATE SET
    u1.prop1 = val1,
    u2.prop2 = val2,
    r.prop3 = val3
ON MATCH SET
    u1.prop1 = newVal1,
    u2.prop2 = newVal2,
    r.prop3 = newVal3

Have a look at the Neo4j docs for "MERGE".

like image 179
BtySgtMajor Avatar answered Apr 06 '23 21:04

BtySgtMajor