2016-04-24 12 views
2

私のデータベースには以下のものがあります。Neo4jのノードのIDのリストと共にノードのリストを取得する

[ 
    { 
     id: 1, 
     username: "Whatever", 
     email: "[email protected]" 
     ... 
    }, 
    [ 6, 7, 8, ... ] 
], 
[ 
    { 
     id: 2, 
     username: "Another user", 
     email: "[email protected]" 
     ... 
    }, 
    [ 15, 16, 17, 18, ... ] 
], 
... 

...数字はノードが直接にに関連しているノードのIDです:友情関係私はこのような構造を取得したいです。

この回答はほとんどが作業を行うことをいくつかのクエリを持っています

Can I find all the relations between two nodes in neo4j?

しかし、私が思いついた最も近いものだった。この構造体を返す

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: "[email protected]" 
     ... 
    }, 
    [ 1, 6 ] 
], 
[ 
    { 
     id: 1, 
     username: "Whatever", 
     email: "[email protected]" 
     ... 
    }, 
    [ 1, 7 ] 
], 
[ 
    { 
     id: 1, 
     username: "Whatever", 
     email: "[email protected]" 
     ... 
    }, 
    [ 1, 8 ] 
], 
[ 
    { 
     id: 2, 
     username: "Another user", 
     email: "[email protected]" 
     ... 
    }, 
    [ 2, 15 ] 
], 
[ 
    { 
     id: 2, 
     username: "Another user", 
     email: "[email protected]" 
     ... 
    }, 
    [ 2, 16 ] 
], 
... 

多くの冗長データが返されているので、それは良くありません。

このため、適切なCypherクエリは何でしょうか?

ありがとうございます!

答えて

2

私はあなたが物事を複雑にしているか、問題を正しく理解していないと思います。このようなものはあなたのために働きますか?

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