Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
09-30-2020 03:09 AM
Hi,
I need to get all nodes and relationships related to a given node.
For example, I have a node "Person", and it's related to node "Family", node "City", node "Car" and node "Bank":
Person [PartOf]-> Family
Person [BornIn]-> City
Person [Own]-> Car
Person [CustomerOf]-> Bank
How can I get in a query the Person and all its relationships and related nodes?
Thanks.
09-30-2020 03:23 AM
Hello @elad and welcome to the Neo4j community
MATCH path=(:Person)-[]->()
RETURN path
Regards,
Cobra
09-30-2020 04:45 AM
Thank you @Cobra
I guess I didn't explain myself clearly.
Your query will give me multiple results for each Person, right?
I'm aiming for 1 result for each person.
Let's say I have 5 persons with those links, so I want a query that will return a list of results, each result will be a unique person and its relationships and nodes.
So if I query in my case for a Person and all the relationships and related nodes, I want to get 5 result, and each result will contain all the other nodes.
Thanks.
09-30-2020 04:59 AM
This query will return for each Person a list of relations and a list of nodes
MATCH (p:Person)-[r]->(n)
RETURN p, collect(r) AS relations, collect(n) AS nodes
All the sessions of the conference are now available online