Reputation: 516
How should we sort list of tuples in cypher .
MATCH (n)
WHERE EXISTS(n.docId)
WITH COLLECT(DISTINCT [n.docId,n.senId]) as docs ORDER BY docs[0]
RETURN docs
The above query returns :
[[848613, 1], [848613, 2], [848514, 1], [90029, 2], [848681, 1], [575833, 2], [847627, 1], [849538, 2]]
What is the efficient way to achieve this sorted result :
[[90029, 2],[849538, 2],[848681, 1],[848613, 1],[848613, 2],[848514, 1],[847627, 1],[575833, 2]]
Upvotes: 1
Views: 1863
Reputation: 66947
This is a simpler form of @sus's answer:
MATCH (n)
WHERE EXISTS(n.docId)
WITH DISTINCT [n.docId, n.senId] as ds ORDER BY ds
RETURN COLLECT(ds) as docs
Upvotes: 2
Reputation: 516
I tried around and figured out this answer :
MATCH (n)
WHERE EXISTS(n.docId)
WITH DISTINCT [n.docId,n.senId] as ds ORDER BY ds[0],ds[1]
WITH COLLECT(ds) as docs
RETURN docs
Upvotes: 2