对于以下数据:
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'});
Run Code Online (Sandbox Code Playgroud)
这个查询
MATCH p=(n:Attendee)-[r*0..1]-(m)
WITH p order by head(nodes(p)).name
return collect(distinct(p))
Run Code Online (Sandbox Code Playgroud)
当通过长度为1的shell返回路径执行时,按路径中第一个节点的名称排序.
但是,通过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"]}
]}]}
Run Code Online (Sandbox Code Playgroud)
不维护相同的顺序(看起来它是由节点ID排序的).
如何修复我的Cypher给我与通过shell执行时相同的结果?
PS.如果resultDataContents是"row",并且在REST中没有使用COLLECT,则工作正常
在这种情况下不需要收集。
return distinct p应该足够了。
在 resultDataContents“graph”中,它使用集合重新处理响应,以唯一地收集响应的节点和关系。订单很可能会丢失。