在Neo4j中检索节点列表以及与它们直接相关的节点的ID列表

在我的数据库中,我有:用户节点,它们通过:友谊关系相关。 我想要得到这样的结构:

[ { id: 1, username: "Whatever", email: "whatever@test.com" ... }, [ 6, 7, 8, ... ] ], [ { id: 2, username: "Another user", email: "anotheruser@test.com" ... }, [ 15, 16, 17, 18, ... ] ], ... 

…其中数字是节点与a:友谊关系直接相关的节点的ID。

这个答案有一些疑问, 几乎做的工作:

我能findneo4j中两个节点之间的所有关系吗?

但是我提出的最接近的是:

 match p=(a:User)-[:Friendship]->(d:User) return d, reduce(nodes = [],n in nodes(p) | nodes + [id(n)]) as node_id_col 

…它返回这个结构:

 [ { id: 1, username: "Whatever", email: "whatever@test.com" ... }, [ 1, 6 ] ], [ { id: 1, username: "Whatever", email: "whatever@test.com" ... }, [ 1, 7 ] ], [ { id: 1, username: "Whatever", email: "whatever@test.com" ... }, [ 1, 8 ] ], [ { id: 2, username: "Another user", email: "anotheruser@test.com" ... }, [ 2, 15 ] ], [ { id: 2, username: "Another user", email: "anotheruser@test.com" ... }, [ 2, 16 ] ], ... 

这不好,因为它返回了大量的冗余数据。

那么Cypher对此有什么疑问呢?

谢谢!

我想你可能是在复杂的事情或我不正确的理解这个问题。 像这样的东西对你有用吗?

 match (a:User)-[:Friendship]->(d:User) return a, collect(id(d))