我需要列出节点D1和D1.A1.B1
之间节点的所有部门节点和关联用户我需要一个Cypher查询。
结果应该是部门: D1,D1.A1,D1.A1.B1 和用户:U1,U2,U4
答案 0 :(得分:1)
使用variable-length pattern matching,nodes(),unwind
和collect()
的以下Cypher查询应该有效。评论说明:
// match the entire path from 'D1' to 'D1.A1.B1'
match p = ( {name : 'D1'} )-[*]->( {name : 'D1.A1.B1'} )
// get all nodes (departments) from path
with nodes(p) as deps
// unwind deps collection to individual departments
unwind deps as dep
// match workers and managers directly connected to dep nodes
match (dep)<-[:WORKER|:MANAGER]-(u:User)
return collect(dep) as departments, collect(u) as users