Neo4j Combine multiple shortcuts

There is a situation where I need to match any node label.

We can do this for relationship types such as

(n)-[:KNOWS|LOVES]->(m)

Is it possible to map node labels like this? eg.

MATCH (c:computer)<-[:belongs_to]-(comp:HP|IBM)
return comp

I have tried this currently and it gives results, is there an easier way?

MATCH (c:computer)<-[:belongs_to]-(comp)
WHERE 'HP' IN labels(comp) OR  'IBM' IN labels(comp)
return comp
+4
source share
3 answers

I think

WHERE 'HP' IN labels(comp) OR  'IBM' IN labels(comp)

AND

WHERE comp:HP OR comp:IBM

Will work just like the second, easy to use

+6
source

This form of your last request is at least easier to write and more understandable:

MATCH (c:computer)<-[:belongs_to]-(comp)
WHERE comp:HP OR comp:IBM
return comp;
+1
source

.

, ( !), , :

MATCH (n:computer)
WHERE any(label in labels(n) WHERE label in ['HP', 'IBM'])
RETURN n
0

All Articles