I have some nodes and relation like A -> B ->C -> D
; andB->D
So the B C D is a loop, now I want get all relations and each relation distance from node A;
I expect result like:
{startNode: A, endNode: B, rel:FRIEND, distanceFromAtoEndnode: 1},
{startNode: B, endNode: C, rel:FRIEND, distanceFromAtoEndnode: 2},
{startNode: C, endNode: D, rel:FRIEND, distanceFromAtoEndnode: 3},
{startNode: B, endNode: D, rel:FRIEND, distanceFromAtoEndnode: 2}
and my cypher:
match p=(n:Person {name:"A"})-[r*1..9]-(m:Person) return last(r) as rel,length(p) as distanceFromAtoEndnode
but this always get one more item I donot need:
{startNode: D, endNode: C, rel:FRIEND, distanceFromAtoEndnode: 3},
and if there are double loop like "8" then the result is worse
how can I write the cypher?