apoc.create.removeLabels
Syntax |
|
||
Description |
Removes the given labels from the given |
||
Input arguments |
Name |
Type |
Description |
|
|
The node to remove labels from. |
|
|
|
The labels to remove from the given node. |
|
Return arguments |
Name |
Type |
Description |
|
|
The updated node. |
Remove labels using Cypher
Labels can be referenced dynamically in Cypher without using APOC.
REMOVE n:$(label)
The dynamically calculated label must evaluate to a STRING
or LIST<STRING>
.
For more information, see the Cypher Manual → Dynamically removing a label.
Usage Examples
The examples in this section are based on the following sample graph:
CREATE (jennifer:Person:US {name: "Jennifer", community: 1, partition: 4})
CREATE (karin:Person:US {name: "Karin", community: 4, partition: 2})
CREATE (mark:Person:UK {name: "Mark", community: 3, partition: 3});
The following removes all labels except Person
from all nodes:
CALL db.labels()
YIELD label WHERE label <> "Person"
WITH collect(label) AS labels
MATCH (p:Person)
WITH collect(p) AS people, labels
CALL apoc.create.removeLabels(people, labels)
YIELD node
RETURN node, labels(node) AS labels;
node | labels |
---|---|
(:Person {name: "Jennifer", partition: 4, community: 1}) |
["Person"] |
(:Person {name: "Karin", partition: 2, community: 4}) |
["Person"] |
(:Person {name: "Mark", partition: 3, community: 3}) |
["Person"] |
The Cypher equivalent to this is:
CALL db.labels()
YIELD label WHERE label <> "Person"
WITH collect(label) AS labels
MATCH (p:Person)
FOREACH(l IN labels | REMOVE p:$(l))
RETURN p, labels(p) AS labels;