neo4j - 使用 resultDataContents=graph 通过 REST API 返回集合时,为什么排序顺序会丢失

标签 neo4j cypher

对于以下数据:

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'});

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

当通过 shell 执行时,返回长度为 1 的路径,按路径中第一个节点的名称排序。

但是,通过 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"]}
]}]}

不保持相同的顺序(看起来它是按节点 id 排序的)。

如何修复我的 Cypher 以获得与通过 shell 执行时相同的结果?

附注。如果 resultDataContents 是“行”并且在 REST 中没有使用 COLLECT,则工作正常

最佳答案

在这种情况下不需要收集。
return distinct p应该够了。

在 resultDataContents“图形”中,它使用集合重新处理响应以唯一地收集响应的节点和关系。很可能在那里订单丢失了。

关于neo4j - 使用 resultDataContents=graph 通过 REST API 返回集合时,为什么排序顺序会丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30301462/

相关文章:

unix - 如何在密码查询中检查节点值的数据类型?

java - Neo4j 数据检索中出现空点异常

neo4j - 计算结果中的重复项数

clojure - 尝试删除所有节点+rels 会抛出 "Expected to be in a transaction but wasn' t"

stored-procedures - Neo4J/APOC - 调用存储过程 `apoc.cypher.doIt` 后无法构建查询

database - Neo4j 是否将整个节点图带到 RAM 中以执行单个查询?

performance - 创建独特并缓慢合并

neo4j - 如何使用密码验证路径中是否存在某些节点

arrays - 当Cypher中数组的元素大于零时,我如何计算它们?

python - py2neo.database.status.Neo4j 3.0.3 未经授权