apoc.create.setLabels
Syntax |
|
||
Description |
Sets the given labels to the given |
||
Input arguments |
Name |
Type |
Description |
|
|
The nodes to set labels on. |
|
|
|
The labels to set on the given nodes. |
|
Return arguments |
Name |
Type |
Description |
|
|
The updated node. |
Set labels using Cypher
Labels can be referenced dynamically in Cypher without using APOC.
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, as well as removing any other labels, by running the following query:
MATCH (n:Movie)
CALL apoc.create.setLabels( n, [ n.genre ] )
YIELD node
REMOVE node.genre
RETURN node;
node |
---|
(:Drama {title: "A Few Good Men"}) |
The Cypher equivalent to this is:
MATCH (n:Movie)
REMOVE n:$(labels(n))
SET n:$(n.genre)
REMOVE n.genre
RETURN n;
If we want to only add new labels and not remove existing ones, see apoc.create.addLabels