When I try to execute a shortestPath() function between a Person node and a Movie node, like -
MATCH p=shortestPath((:Person)-[*1..4]->(:Movie))
RETURN length(p)
This fails with the error -
Neo.ClientError.Statement.SyntaxError
shortestPath(...) requires named nodes (line 1, column 9 (offset: 8))
"MATCH p=shortestPath((:Person)-[*1..4]->(:Movie))"
^
To fix this, I must assign the node labels to variables, like so -
MATCH pt=shortestPath((p:Person)-[*1..4]->(m:Movie))
RETURN length(pt)
This produces the correct return -
length(pt)
1
1
1
1
1
1
1
1
2
2
3
and so on.
Why is this required? I'm not using the variables p or m anywhere in my RETURN clause.
I couldn't find an explanation in the shortestPath() documentation.