Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
10-03-2018 05:48 PM
Looking for a syntax like "IN [list]" that will work with multiple labels so I can set a property on every node of those types. Something like:
MATCH (n) WHERE n:Label IN [FIRST,SECOND...TENTH] SET n.prop = "true"
or
MATCH (n {Label IN [FIRST,SECOND...TENTH]}) SET n.prop = "true"
I can find IN syntax for properties, and I can see how to match a single node label, but I can't see how to match multiple labels. Not too bad to issue multiple commands when there are just one or two labels to affect, but when there is a long list...
Thanks.
10-03-2018 06:01 PM
This is actually a tricky one. While you could manually match on nodes of each label (WHERE n:FIRST OR n:SECOND ...
), there isn't a good way to do this using a list of labels, as dynamic label matches aren't generally supported with Cypher (labels usually need to be hardcoded so the Cypher planner can build a plan before query execution).
That said, you could use APOC Procedures for this, allowing you to build the queries you need based on the label list. Provided you pass in a $labels parameter which is a list of labels:
UNWIND $labels as label
CALL apoc.cypher.run('MATCH (n:' + label + ') RETURN n', {}) YIELD value
WITH value.n as n
SET n.prop = true
Make sure the labels passed in are sanitized first, if coming (directly or indirectly) from user input, to avoid Cypher injection.
All the sessions of the conference are now available online