I have nodes without label but a property NodeType
Is there a way to set the label of those nodes with the value of the NodeType property?
Thanks!
Create a Node with Multiple Labels To create multiple labels with a single node, you have to specify the labels for the node by separating them with a colon " : ". Syntax: CREATE (node:label1:label2:. . . . labeln)
propkeys — Property keys Property keys in the Neo4j database, returned as a cell array of character vectors. Each character vector denotes a property key.
Label is a name or identifier to a Node or a Relationship in Neo4j Database. We can say this Label name to a Relationship as "Relationship Type". We can use CQL CREATE command to create a single label to a Node or a Relationship and multiple labels to a Node.
APOC is an add-on library for Neo4j that provides hundreds of procedures and functions adding a lot of useful functionality. The library covers a lot of things, that's why we provide a searchable Overview of all APOC functions and procedures.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With