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
  •  | 
  •  

Question

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?

Était-ce utile?

La solution

How about this:

MATCH p = shortestPath((element)-[:LINKS*..3]-(user))
WHERE element <> user
RETURN length(p)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top