Removing properties and labels from graph elements is done using REMOVE
.
For deleting nodes and relationships, see Section 11.5, “Delete”.
Note | |
---|---|
Removing labels from a node is an idempotent operation: If you try to remove a label from a node that does not have that label on it, nothing happens. The query statistics will tell you if something needed to be done or not. |
The examples start out with the following database:
Neo4j doesn’t allow storing null
in properties. Instead, if no value exists, the property is just not there. So, to remove a property value on a node or a relationship, is also done with REMOVE
.
Query.
MATCH (andres { name: 'Andres' }) REMOVE andres.age RETURN andres
The node is returned, and no property age
exists on it.
Try this query live. create (_0:`Swedish` {`age`:25, `name`:"Tobias"}) create (_1:`Swedish`:`German` {`age`:34, `name`:"Peter"}) create (_2:`Swedish` {`age`:36, `name`:"Andres"}) create _2-[:`KNOWS`]->_0 create _2-[:`KNOWS`]->_1 match (andres {name: 'Andres'}) remove andres.age return andres
To remove labels, you use REMOVE
.
Query.
MATCH (n { name: 'Peter' }) REMOVE n:German RETURN n
Try this query live. create (_0:`Swedish` {`age`:25, `name`:"Tobias"}) create (_1:`Swedish`:`German` {`age`:34, `name`:"Peter"}) create (_2:`Swedish` {`age`:36, `name`:"Andres"}) create _2-[:`KNOWS`]->_0 create _2-[:`KNOWS`]->_1 match (n {name: 'Peter'}) remove n:German return n
To remove multiple labels, you use REMOVE
.
Query.
MATCH (n { name: 'Peter' }) REMOVE n:German:Swedish RETURN n
Try this query live. create (_0:`Swedish` {`age`:25, `name`:"Tobias"}) create (_1:`Swedish`:`German` {`age`:34, `name`:"Peter"}) create (_2:`Swedish` {`age`:36, `name`:"Andres"}) create _2-[:`KNOWS`]->_0 create _2-[:`KNOWS`]->_1 match (n {name: 'Peter'}) remove n:German:Swedish return n
Copyright © 2014 Neo Technology