Cypher / Preventing shortestPath function to retrieve nodes that don't involve at least one traversed relationship

StackOverflow https://stackoverflow.com/questions/22564755

  •  18-06-2023
  •  | 
  •  

문제

Regarding this excerpt of cyper request: (assuming element is a known node variable in the whole request)

MATCH p = shortestPath(element-[:LINKS*..3]-(user))
RETURN length(p)

Assuming that one element might be a user, how could I prevent retrieving in the result the element representing the user itself?

It would be cool if we could do:

MATCH p = shortestPath(element-[:LINKS*1..3]-(user))
RETURN length(p)

But it leads to this error:

shortestPath(...) does not support a minimal length

What is the most efficient way to achieve this trick?

도움이 되었습니까?

해결책

How about this:

MATCH p = shortestPath((element)-[:LINKS*..3]-(user))
WHERE element <> user
RETURN length(p)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top