Updating properties on nodes and relationships is done with the SET
clause.
SET
can also be used with maps from parameters.
The examples use this graph as a starting point:
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.
Try this query live. (1) {"age":34,"name":"Peter"} (2) {"age":36,"awesome":true,"name":"Andres"} (2)-[:KNOWS]->(1) {} start n = node(2) set n.surname = 'Taylor' return n
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.
Try this query live. (1) {"age":34,"name":"Peter"} (2) {"age":36,"awesome":true,"name":"Andres"} (2)-[:KNOWS]->(1) {} start n = node(2) set n.name = null return n
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.
Try this query live. (1) {"age":34,"name":"Peter"} (2) {"age":36,"awesome":true,"name":"Andres"} (2)-[:KNOWS]->(1) {} start at = node(2), pn = node(1) set at = pn return at, pn
Copyright © 2013 Neo Technology