apoc.create.addLabels

Details

Syntax

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

Description

Adds the given labels to the given NODE values.

Input arguments

Name

Type

Description

nodes

ANY

The nodes to add labels to.

labels

LIST<STRING>

The labels to add to the nodes.

Return arguments

Name

Type

Description

node

NODE

The updated node.

Set labels using Cypher

Labels can be referenced dynamically in Cypher without using APOC.

Cypher syntax for setting a label dynamically
SET n:$(label)

The dynamically calculated label must evaluate to a STRING or LIST<STRING>. For more information, see the Cypher Manual → Dynamically setting a label.

Usage Examples

The examples in this section are based on the following sample graph:

CREATE (:Movie {title: 'A Few Good Men', genre: 'Drama'});

We can move the 'genre' property to a label and remove it as a property by running the following query:

MATCH (n:Movie)
CALL apoc.create.addLabels( n, [ n.genre ] )
YIELD node
REMOVE node.genre
RETURN node;
Results
node

(:Movie:Drama {title: "A Few Good Men"})

The Cypher equivalent to this is:

MATCH (n:Movie)
SET n:$(n.genre)
REMOVE n.genre
RETURN n;