15.20. Set

15.20.1. Set a property
15.20.2. Remove a property
15.20.3. Copying properties between nodes and relationships

Updating properties on nodes and relationships is done with the SET clause. SET can also be used with maps from parameters.

15.20.1. Set a property

To set a property on a node or relationship, use SET.

Query. 

START n = node(2)
SET n.surname = 'Taylor'
RETURN n

The newly changed node is returned by the query.

Result

n
1 row
Properties set: 1
0 ms

Node[2]{name:"Andres",age:36,awesome:true,surname:"Taylor"}


Try this query live. (1) {"age":34,"name":"Peter"} (2) {"age":36,"awesome":true,"name":"Andres","surname":"Taylor"} (2)-[:KNOWS]->(1) {} start n = node(2) set n.surname = 'Taylor' return n

15.20.2. Remove a property

Normally you remove a property by using delete, but it’s sometimes handy to do it using the SET command. One example is if the property comes from a parameter.

Query. 

START n = node(2)
SET n.name = null
RETURN n

The node is returned by the query, and the name property is now missing.

Result

n
1 row
Properties set: 1
0 ms

Node[2]{awesome:true,age:36}


Try this query live. (1) {"age":34,"name":"Peter"} (2) {"age":36,"awesome":true} (2)-[:KNOWS]->(1) {} start n = node(2) set n.name = null return n

15.20.3. Copying properties between nodes and relationships

You can also use SET to copy all properties from one graph element to another. Remember that doing this will remove all other properties on the receiving graph element.

Query. 

START at = node(2), pn = node(1)
SET at = pn
RETURN at, pn

The Andres node has had all it’s properties replaced by the properties in the Peter node.

Result

atpn
1 row
Properties set: 3
0 ms

Node[2]{name:"Peter",age:34}

Node[1]{name:"Peter",age:34}


Try this query live. (1) {"age":34,"name":"Peter"} (2) {"age":34,"name":"Peter"} (2)-[:KNOWS]->(1) {} start at = node(2), pn = node(1) set at = pn return at, pn