3.14. REMOVE

The REMOVE clause is used to remove properties from nodes and relationships, and to remove labels from nodes.

3.14.1. Introduction

For deleting nodes and relationships, see Section 3.12, “DELETE”.

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 use the following database:

Figure 3.13. Graph
alt

3.14.2. Remove a property

Neo4j doesn’t allow storing null in properties. Instead, if no value exists, the property is just not there. So, REMOVE is used to remove a property value from a node or a relationship.

Query. 

MATCH (a { name: 'Andy' })
REMOVE a.age
RETURN a.name, a.age

The node is returned, and no property age exists on it.

Table 3.108. Result
a.name a.age

1 row Properties set: 1

"Andy"

<null>

Try this query live.  CREATE (a:Swedish {name: 'Andy', age: 36}), (t:Swedish {name: 'Timothy', age: 25}), (p:German:Swedish {name: 'Peter', age: 34}), (a)-[:KNOWS]->(t), (a)-[:KNOWS]->(p) MATCH (a {name: 'Andy'}) REMOVE a.age RETURN a.name, a.age

3.14.3. Remove all properties

REMOVE cannot be used to remove all existing properties from a node or relationship. Instead, using SET with = and an empty map as the right operand will clear all properties from the node or relationship.

3.14.4. Remove a label from a node

To remove labels, you use REMOVE.

Query. 

MATCH (n { name: 'Peter' })
REMOVE n:German
RETURN n.name, labels(n)

Table 3.109. Result
n.name labels(n)

1 row Labels removed: 1

"Peter"

["Swedish"]

Try this query live.  CREATE (a:Swedish {name: 'Andy', age: 36}), (t:Swedish {name: 'Timothy', age: 25}), (p:German:Swedish {name: 'Peter', age: 34}), (a)-[:KNOWS]->(t), (a)-[:KNOWS]->(p) MATCH (n {name: 'Peter'}) REMOVE n:German RETURN n.name, labels(n)

3.14.5. Remove multiple labels from a node

To remove multiple labels, you use REMOVE.

Query. 

MATCH (n { name: 'Peter' })
REMOVE n:German:Swedish
RETURN n.name, labels(n)

Table 3.110. Result
n.name labels(n)

1 row Labels removed: 2

"Peter"

[]

Try this query live.  CREATE (a:Swedish {name: 'Andy', age: 36}), (t:Swedish {name: 'Timothy', age: 25}), (p:German:Swedish {name: 'Peter', age: 34}), (a)-[:KNOWS]->(t), (a)-[:KNOWS]->(p) MATCH (n {name: 'Peter'}) REMOVE n:German:Swedish RETURN n.name, labels(n)