Why the sort order is lost when returning the collection via the REST API using resultDataContents = graph

For the following data:

create (a:Attendee {name:'luanne'}); create (a:Attendee {name:'adam'}); create (a:Attendee {name:'christoph'}); create (a:Attendee {name:'vince'}); create (a:Attendee {name:'michal'}); 

this request

 MATCH p=(n:Attendee)-[r*0..1]-(m) WITH p order by head(nodes(p)).name return collect(distinct(p)) 

when executed through shell return paths of length one, ordered by the name of the first node in the path.

However, through the REST API:

 POST http://localhost:7474/db/data/transaction/commit {"statements":[ {"statement":"MATCH p=(n:`Attendee`)-[r*0..1]-(m) WITH p order by head(nodes(p)).name return collect(distinct(p))","parameters":{},"resultDataContents":["graph"]} ]}]} 

the same order is not supported (looks like it is ordered by node identifier).

How to fix my Cypher to give me the same results as when running through the shell?

PS. Works great if resultDataContents is a string, and also when COLLECT is not used in REST

+5
source share
1 answer

In this case, a fee is not needed.

return distinct p should be enough.

In resultDataContents "graph", it processes the response using sets to collect nodes and relationships for the answer uniquely. It is very likely that the order will be lost.

+1
source

All Articles