Reputation: 815
How do I order my results by node property?
RETURN DISTINCT p, COLLECT(DISTINCT {personID: person.id, personName: person.name, personOrder: person.orderNumber}) AS personInfo
I've tried ORDER BY personOrder
but it doesn't seem to work.
Any ideas?
Thanks.
Upvotes: 0
Views: 48
Reputation: 4052
We can't sort the collection directly. Collection can be sorted with UNWIND and ORDER BY. Then collect again. Another way is to sort on the these before collecting.
Replace RETURN
by WITH
. Sort and Collect again:
WITH p, COLLECT(DISTINCT {personID: person.id, personName: person.name, personOrder: person.orderNumber}) AS personInfo
UNWIND personInfo AS person
WITH p, person ORDER BY person.personOrder
RETURN p, collect(person) AS personInfo;
Upvotes: 2