Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
12-19-2018 05:10 PM
I have a generic node labeled 'Person'.
how can I add a new dynamic label to the node?
SET labels(n) += n.nome returns an error
SET n:n.nome returns an error on .
any idea?
12-19-2018 06:37 PM
Normally with Cypher labels and relationship types must be hard-coded, as the query planner uses this information when planning the query (before any execution can even take place).
That said, we do have a workaround via the APOC Procedures library via apoc.create.addLabels().
Here's an example:
MATCH (n:Persona)
WITH n, n.nome as nome
CALL apoc.create.addLabels(n, [nome]) YIELD node
RETURN count(n) as count
12-20-2018 05:43 AM
Why would you add a name as a label, that doesn't make any sense?
12-20-2018 07:16 AM
@michael.hunger you are completely right. You can search as deep as you like but it is really difficult to find some meaningfull reason for this.
But it is a simple example to show that I have to add a label unknown at the query write time, which can depend by the parameter content or the return value of another query. In this case, it starts to have some sense.
11-10-2019 10:12 PM
Here's one.
I built a generic tool to import any kind of data where the label is unknown at the time of importing but part of the data itself. If the data can be described in terms of Nodes with a Name, Label, Properties and Values or Relations between Nodes with Properties and Values, the CQL to import that data can be reused without the need to modify it to the current data model. It depends on being able to dynamically add a Label, though.
If there is a better way to import any data model, I'd love to hear about it, because I can see that dynamically adding Labels is not ideal.
11-11-2019 04:40 PM
You can use some of the apoc procedures to create dynamic labels and rel-types or something like apoc.graph.fromDocument to turn nested documents automatically into graphs.
https://neo4j.com/docs/labs/apoc/current/graph-updates/data-creation/
All the sessions of the conference are now available online