neo4j - how to set label with property value
No, currently there is no possibility to define a label with a variable.
You'll have to do it in your application by fetching all nodes that you want to add a label on it and sending a Cypher Query to add this label.
A quick example in PHP :
$nodes = $client->sendCypherQuery('MATCH (n) WHERE n.nodeType = "MyType" RETURN n');
foreach ($nodes as $node) {
$label = $node->getProperty('nodeType');
$id = $node->getId();
$client->sendCypherQuery('MATCH (n) WHERE id(n) = '.$id.' SET n :'.$label;
}
You can't use a variable but you can still do it in a cypher query (or at least a few of them) rather than a script. If you only have a handful of different labels this probably works well but not that scalable for many labels.
MATCH (n)
WHERE length(labels(n)) = 0
AND n.type = 'XX'
SET n:XX;
MATCH (n)
WHERE length(labels(n)) = 0
AND n.type = 'XY'
SET n:XY;