HanXu
HanXu

Reputation: 5597

Neo4j create if not exist otherwise update

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?

Upvotes: 4

Views: 1782

Answers (1)

BtySgtMajor
BtySgtMajor

Reputation: 1462

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".

Upvotes: 7

Related Questions