Search code examples
neo4jneo4jclient

Neo4jClient Get All Referenced Nodes


In my application I have classes/nodes like:
-person
-activity
-company

I can create relationships between:
- person and company
- company and activity
- activity and person - person and person
- company and company

So. It is possible, that a specific activity is related to a person and to an company. The company is mostly the root. But there is no real hierarchy. It's more like a mesh structure.

(I know how to create the relationships etc. I saw already some tutorials. :) )

Now. I want to get all directly related relationships with nodes of a specific node. I DON'T want to fetch the related data by the relationship type. I want (when possible) one query, which reads all relationships and the according nodes.
And the second requirement: When I have retrieved all related relationships and nodes, I want get the relationships (if any exists) between these nodes!

So it would be very cool to solve this with 2 queries!

Any ideas?

Thanks!


Solution

  • How about something like

    start company = node(2) match company-[?:employs]-> person return company, person
    

    See docs.neo4j.org/chunked/snapshot/cypher-query-lang.html for details.

    Otherwise, you can look up the companies, persons etc in an index, e.g.

    start comp=node:Companies(name='Cocal Cola'), person=node:Persons(name='Bob') ...
    

    Is that what you are looking for ?