zsayn zsayn - 2 years ago 113
Node.js Question

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:


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

Answer Source

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

MATCH (u : User)-[r:CREATE]->(p: Project) 
RETURN u, collect(p), collect(rec)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download