Node.js 在Neo4j中检索节点列表以及与其直接相关的节点ID列表
在我的数据库中,我有:User节点,它们通过:友谊关系关联。我想得到一个这样的结构:Node.js 在Neo4j中检索节点列表以及与其直接相关的节点ID列表,node.js,neo4j,cypher,Node.js,Neo4j,Cypher,在我的数据库中,我有:User节点,它们通过:友谊关系关联。我想得到一个这样的结构: [ { id: 1, username: "Whatever", email: "whatever@test.com" ... }, [ 6, 7, 8, ... ] ], [ { id: 2, username: "Another user", email: "ano
[
{
id: 1,
username: "Whatever",
email: "whatever@test.com"
...
},
[ 6, 7, 8, ... ]
],
[
{
id: 2,
username: "Another user",
email: "anotheruser@test.com"
...
},
[ 15, 16, 17, 18, ... ]
],
...
…其中,数字是该节点与:友谊关系直接相关的节点的ID
这个答案有一些问题几乎可以解决:
但最接近我的是:
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 ]
],
...
这并不好,因为它返回了大量冗余数据
那么,什么才是正确的密码查询呢
谢谢 我想你可能把事情复杂化了,或者我没有正确理解这个问题。像这样的东西对你有用吗
match (a:User)-[:Friendship]->(d:User)
return a, collect(id(d))