Say I have have matched a start node and now have its id.
Next I want to find all the nodes along incoming paths to my start node that have a certain label. I don't know how "distant" nodes with that label are (but think they will be less than 20 nodes away). If there are any related nodes with that label, they will all be the same distance away.
At the moment I'm doing:
MATCH (l:`mylabel`)-[*1..20]->(start) where id(start) = 1016236 RETURN l
But I'm guessing this could potentially be wasteful and inefficient and slow.
I could do something like (in psuedo code):
for $i in (1..20) {
@ls = run_cypher("MATCH (l:`mylabel`)-[*1..$i]->(start) where id(start) = 1016236 RETURN l")
last if @ls
}
But that needs multiple separate queries and is still wasteful.
Is there a better solution?