Hi, there. I've been struggling with this for a bit, so I thought I'd ask here.
How can I get a breadcrumb-like string of the parent/child relationships of nodes in a nested structure?
I basically have a hierarchical group structure that I'm trying to represent, almost like a directory path. It doesn't go very many levels deep (just 3-4), and it doesn't loop or otherwise go infinite.
I'm trying to create strings (as node properties) like this:
'/Root/group/subgroup1/subgroup2' for Group node subgroup2
'/Root/group/subgroup1' for Group node subgroup1
'/Root/group' for Group node group
and just 'Root' for any of the root Group nodes
I can get pretty close with the Cypher below for a single level, but I can't figure out if/how I need to do this recursively or otherwise.
MATCH (p:Group)-[:CONTAINS]->(m:Group) RETURN "/" + p.name + "/" + m.name as trail
which returns strings like this for each node that is contained by another.
I've played around with using APOC to expand and UNWIND nodes in a subgraph, too. I need to figure out how to chase back up to the root, and only run down to the current node (and not beyond).