简体   繁体   中英

Cypher Query Return matched Nodes and optional relationships

I am trying to find the most optimal way of returning all matched nodes and any relationships they might have?

Here's my problem:

I need to return all users who created a project, so

match (u : User)-[r:CREATE]->(p: Project) return u, collect(p)

Simple enough, but User could also have other relationships and I would like to include them or optionally check (return true/false)

For example User could have relationship RECOMMEND, I don't want to limit by it, but if check if it exists an with what node?

Ideally my return table would look like this:

USER1 - PROJECT(S) - RECOMMENDED USER

USER2 - PROJECT(S) - NULL (nobody is recommending)

OPTIONAL MATCH will match the pattern and return null if it does not exist

MATCH (u : User)-[r:CREATE]->(p: Project) 
OPTIONAL MATCH (u)-[:RECOMMEND]->(rec)
RETURN u, collect(p), collect(rec)

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