Graph gist: http://gist.neo4j.org/?6182d024325343760cb4
I want to get a (longest) path in order and it works as expected until I add a COLLECT statement, is there something concerning Cypher and COLLECT that I just don't understand or is this a bug?
This query works as expected, returns the nodes in path in the correct order:
MATCH (n:Cable { name: 'Cable3' })-[:Connected_to*]-(port:Port)
OPTIONAL MATCH path=(port)-[:Connected_to*]-()
WITH nodes(path) AS parts, length(path) AS len
ORDER BY len DESC
LIMIT 1 UNWIND parts AS part
RETURN part
This one, without the COLLECT statement, returns the nodes in the right order but also the nodes between the part and the parent (as expected).
MATCH (n:Cable { name: 'Cable3' })-[:Connected_to*]-(port:Port)
OPTIONAL MATCH path=(port)-[:Connected_to*]-()
WITH nodes(path) AS parts, length(path) AS len
ORDER BY len DESC
LIMIT 1 UNWIND parts AS part
OPTIONAL MATCH (part)<-[:Has*1..10]-(parent)
RETURN part, parent
This query does not work as expected, returns the nodes in the path in another order:
MATCH (n:Cable { name: 'Cable3' })-[:Connected_to*]-(port:Port)
OPTIONAL MATCH path=(port)-[:Connected_to*]-()
WITH nodes(path) AS parts, length(path) AS len
ORDER BY len DESC
LIMIT 1 UNWIND parts AS part
OPTIONAL MATCH (part)<-[:Has*1..10]-(parent)
RETURN part, LAST(COLLECT(parent))
Any insight would be appreciated.