简体   繁体   中英

In neo4j how to return specific nodes or relationship with cypher?

You are given two arrays one for some labels and another for some relationships and you are asked to return the nodes and their relationships which are found only in the arrays you where given. I tried different approach to it but I couldn't get a better cipher to return the graph with respect to both arrays

MATCH (n)-[r]-(m) where n in ["username"] and r in ["knows"] return n,r

The code above, I know its completely wrong but it kinda shows the idea, share your thoughts 😁

This should work:

MATCH (n)-[r]-(m)
WHERE ANY(l IN labels(n) WHERE l IN ['username','label2'])
      AND type(r) IN ['knows','relType2']
RETURN n,r,m 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM