apoc.create.addLabels
Syntax |
|
||
Description |
Adds the given labels to the given |
||
Input arguments |
Name |
Type |
Description |
|
|
The nodes to add labels to. |
|
|
|
The labels to add to the nodes. |
|
Return arguments |
Name |
Type |
Description |
|
|
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;
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;