count() is an aggregate function . When using any aggregate function, the resulting rows will be grouped by all RETURN and non- aggregated functions included in the sentence. In this case, the result rows will be grouped by p , and the return value will be counted (nodes (p)).
nodes(p) returns an array of nodes, so count(nodes(p)) returns the number of arrays and will always be 1 .
To return the number of nodes in a path, you should use size(nodes(p)) .
If you are just interested in the length of the path and not especially in the nodes that are included in it, I would recommend that you use length(p) . This will return the length in rels for the given path without the need for manipulation / access to nodes.
source share