How to return nodes between a node and the top of a tree in neo4j -
How to return nodes between a node and the top of a tree in neo4j -
i trying larn neo4j , going start basic employee / employer illustration employee has manager unless @ top of tree.
my construction looks employee->managedby->manager->managedby->manager->managedby->manager. each manger can have multiple employees or managers under them.
what able list of managers between employee , main boss(ceo/president/whatever).
initially started off query this
match(baseemployee {name: 'josh'})-[:managedby*0..]-(managers) homecoming managers.name; this seems not show manager , his/her manager , on seems show manage when want show list like
josh, boss, bossboss, bossbossboss, ceo after searching , luck managed closer using next query
match p=(baseemployee {name: 'josh'})-[:managedby*0..]-(managers) not(managers-[:managedby]->()) homecoming p; i learning neo4j best guess of happening here path myself first manager doesn't have managedby relationship. issue returns path , prefer have list of managers.
is possible without doing p= query?
you must add together direction of relationship path query! otherwise explore downwards josh.
and if start varlength query @ 0 0.. homecoming josh too. default 1.. can leave off.
you can homecoming nodes of path nodes(p).
match p=(baseemployee {name: 'josh'})-[:managedby*]->(managers) not(managers-[:managedby]->()) homecoming nodes(p); if want have 1 row per node can 1 of two: either unwind collection rows.
match p=(baseemployee {name: 'josh'})-[:managedby*]->(managers) not(managers-[:managedby]->()) unwind nodes(p) n homecoming n; or homecoming lastly node of each path root.
match p=(baseemployee {name: 'josh'})-[:managedby*]->(managers) homecoming managers; neo4j
Comments
Post a Comment