Chris
Chris

Reputation: 815

Neo4J - Ordering results (list of maps) by node property

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

Answers (1)

Rajendra Kadam
Rajendra Kadam

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

Related Questions