apoc.create.removeLabels

Details

Syntax

apoc.create.removeLabels(nodes, labels) :: (node)

Description

Removes the given labels from the given NODE values.

Input arguments

Name

Type

Description

nodes

ANY

The node to remove labels from.

labels

LIST<STRING>

The labels to remove from the given node.

Return arguments

Name

Type

Description

node

NODE

The updated node.

Remove labels using Cypher

Labels can be referenced dynamically in Cypher without using APOC.

Cypher syntax for dynanically removing a label
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;
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"]

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;