SET
MATCH (n) WHERE n.name = 'Alice' SET n.age = 31Update properties or labels on matched nodes and relationships. Automatically updates the updated_at timestamp.
Syntax#
MATCH (variable) WHERE predicate
SET <assignment>[, <assignment>]*Each <assignment> is one of:
| Form | Effect |
|---|---|
n.key = value | Set a single property |
n.key = null | Remove a property (equivalent to REMOVE n.key) |
n:Label | Add a label |
n:Label1:Label2 | Add multiple labels |
n += {key: value, ...} | Merge a property map onto n (existing keys not in the map are preserved) |
n = {key: value, ...} | Replace all properties on n with the map (existing keys not in the map are removed) |
Examples#
Multiple properties in one clause#
MATCH (r:Robot {id: 'r1'})
SET r.battery = 96, r.status = 'charging', r.task = 'standby'Add a label#
MATCH (n:Person {id: 'p1'}) SET n:VerifiedMerge a map#
MATCH (n:Person {id: 'p1'})
SET n += {age: 31, lastSeen: timestamp()}+= keeps any existing properties not mentioned in the map. Use n = {...} instead to replace the full property set.
Parameterized#
MATCH (n:Person {id: $id}) SET n.age = $age, n.role = $roleSee Also#
- MATCH + WHERE — select what to update
- REMOVE — remove properties or labels
- MERGE — find-or-create with
ON CREATE SET/ON MATCH SET
Try it
Open ↗⌘↵ to run
Loading engine…