apoc.create.removeLabels

Procedure

apoc.create.removeLabels(nodes Any, labels [String]) - removes the given labels from the given node(s).

Signature

apoc.create.removeLabels(nodes :: ANY?, labels :: LIST? OF STRING?) :: (node :: NODE?)

Input parameters

Name Type Default

nodes

ANY?

null

labels

LIST? OF STRING?

null

Output parameters

Name Type

node

NODE?

Usage Examples

Cypher supports deleting of labels as long as the labels are hard coded. If the labels are dynamically specified, we can use this procedure.

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;
Table 1. Results
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"]