Updating labels on nodes and properties on nodes and relationships is done with the SET clause.
SET can also be used with maps from parameters to set properties.
| Note | |
|---|---|
Setting labels on a node is an idempotent operations — if you try to set a label on a node that already has that label on it, nothing happens. The query statistics will tell you if something needed to be done or not. |
The examples use this graph as a starting point:
To set a property on a node or relationship, use SET.
Query.
MATCH (n { name: 'Andres' })
SET n.surname = 'Taylor'
RETURN n
The newly changed node is returned by the query.
Normally you remove a property by using REMOVE, but it’s sometimes handy to do
it using the SET command. One example is if the property comes from a parameter.
Query.
MATCH (n { name: 'Andres' })
SET n.name = NULL RETURN n
The node is returned by the query, and the name property is now missing.
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.
MATCH (at { name: 'Andres' }),(pn { name: 'Peter' })
SET at = pn
RETURN at, pn
The Andres node has had all it’s properties replaced by the properties in the Peter node.
Use a parameter to give the value of a property.
Parameters.
{
"surname" : "Taylor"
}
Query.
MATCH (n { name: 'Andres' })
SET n.surname = { surname }
RETURN n
The Andres node has got an surname added.
This will replace all existing properties on the node with the new set provided by the parameter.
Parameters.
{
"props" : {
"name" : "Andres",
"position" : "Developer"
}
}
Query.
MATCH (n { name: 'Andres' })
SET n = { props }
RETURN n
The Andres node has had all it’s properties replaced by the properties in the props parameter.
To set a label on a node, use SET.
Query.
MATCH (n { name: 'Stefan' })
SET n :German
RETURN n
The newly labeled node is returned by the query.
Copyright © 2014 Neo Technology