Reputation: 113
I would like to order the returned outgoing nodes in a specific way, based on a relationship property. Can this customized at all? I can't even find anything in the docs about what the default ordering is.
@Relationship("CREATED")
private List<Node> nodes;
Upvotes: 0
Views: 319
Reputation: 8262
There is no default sorting in Spring Data Neo4j. Also there is no default sorting in the database. You should not make any assumptions if there is no explicit ordering in the query.
If you want to go the path in Cypher you have to define a custom query.
For this, I am referring to the movie graph (:play movies
) to populate the database and have some example data.
If you would call:
MATCH (m:Movie{title:'The Matrix'}) OPTIONAL MATCH (m)<-[:ACTED_IN]-(p) return m, collect(p)
The actors will have a random order. But if you add ordering by e.g. the actor's name to this, you get the desired result.
MATCH (m:Movie{title:'The Matrix'}) OPTIONAL MATCH (m)<-[:ACTED_IN]-(p) WITH m, p ORDER BY p.name return m, collect(p)
Upvotes: 1