Hi guys!
I'am looking for a solution.
Here's the graph
create (n:Node{id:1,closed:false})
create (n)-[:PARENT]->(n1:Node{id:2, closed:true})-[:CHILD]->(n)
create (n1)-[:PARENT]->(n2:Node{id:3, closed:false})-[:CHILD]->(n1)
create (n2)-[:PARENT]->(n3:Node{id:4, closed:true})-[:CHILD]->(n2)
create (n3)-[:PARENT]->(n4:Node{id:5, closed:false})-[:CHILD]->(n3)
create (n4)-[:PARENT]->(n5:Node{id:6, closed:false})-[:CHILD]->(n4)
I need to get the first node from relationship with property
closed = true
I came up with this query, it works for me but I feel that there is better solution for this because I don't need to scan all the nodes above. LIMIT not works here, because I want to change this node after I find it inside the transaction.
I don't know how much nodes above with closed = false.
match v=(p:Node{id:6})-[:CHILD*]->(:Node{closed:true})
with nodes(v) as nodes
UNWIND nodes AS node
with node where node.closed = true
with collect(node)[0] as first
return first
Thanks for your help!