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 query
MATCH p=(n:Attendee)-[r*0..1]-(m)
WITH p order by head(nodes(p)).name
return collect(distinct(p))
when executed via the shell return paths of length one, ordered by the name of the first node in the path.
However, via 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 maintained (looks like it's ordered by the node id).
How do I fix my Cypher to give me the same results as when executed via the shell?
PS. Works fine if resultDataContents is "row" and also when there is no COLLECT used in REST
Collect is not needed in this case.
return distinct p
should be enough.
In resultDataContents "graph" it reprocesses the response using sets to collect nodes and relationships for the response uniquely. Very likely that there the order is lost.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With