Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
01-22-2022 11:57 AM
Hello, This is my first time playing with neo4j, I modeled a graph that looks like this:
A ---> B
A ---> C
B ----> D
B ----> E
C ----> F
now, i my input can contain several nodes, let's say i get "A and B", and i want to find the direct connections of A + the direct ones of B, meaning, to return the nodes:
"B", "C", "D","E"
how to do it in a single query?
01-22-2022 05:42 PM
Try the following:
unwind ['A', 'B'] as input
match(n where n.name = input)
match (n)-[:REL]->(m)
return n.name, collect(m) as children
Replace the literal array ['A','B'] with your parameter containing your inputs. Also, replace the match condition with your unique identifier and the relationship type in the pattern match with yours. The result is a row for each of your inputs, with a list of each input's direct connected nodes.
Test Data:
Result:
If you prefer a list instead of a collection, replace the 'return' clause with this return clause 'return n.name, m', giving the following alternative result:
If you want just a list of the child nodes, replace the return clause with this return clause 'return collect(m)', giving the following result:
All the sessions of the conference are now available online