MERGE

Find-or-create. If the node exists, match it. If not, create it. Safe to run multiple times -- no duplicates.

Syntax#

MERGE (variable:Label {key: value}) [RETURN variable]

Examples#

Idempotent node creation#

MERGE (n:Person {name: 'Alice'}) RETURN n

If a Person node with name: 'Alice' exists, returns it. Otherwise creates it.

Idempotent data loading#

MERGE (n:Person {name: 'Alice'})
MERGE (n:Person {name: 'Bob'})
MERGE (n:Person {name: 'Carol'})

Safe to run multiple times — no duplicates.

See Also#

  • CREATE — always creates new
  • SET — mutate after merge
Try it
Open ↗
Loading engine…