cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Sort properties on path query?

Given the movies data set as an example:

MATCH path=shortestPath((p1:Person)-[*0..15]-(p2:Person))
WHERE toLower(p1.name) = toLower('Tom Hanks') AND toLower(p2.name) = toLower('Halle Berry')
return relationships(path) AS relationships, nodes(path) AS nodes

I'm trying to sort the roles array for each step of the path. When I've needed to do this on nodes, I've used the UNWIND keyword, but that doesn't seem to work on paths.

1 REPLY 1

Hi @SledgeHammer

This is not a complete answer.
You can sort just inside the role as follows.

MATCH path=shortestPath((p1:Person)-[*0..15]-(p2:Person))
  WHERE toLower(p1.name) = toLower('Tom Hanks')
  AND toLower(p2.name) = toLower('Halle Berry')
WITH relationships(path) AS relationships
UNWIND relationships AS relationship
RETURN apoc.coll.sort(relationship.roles) AS roles