cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to Represent Hierarchy and Ordering Between Nodes?

Hi, trying to structure build a graph that models hierarchy between nodes and has a notion of order between siblings. Upon querying, it's important that this hierarchy and order information is preserved.

I've read into apoc.convert.toTree(), and it seems like we can combine that with Cypher to return hierarchical, nested JSON: https://stackoverflow.com/questions/34234373/using-cypher-to-return-nested-hierarchical-json-from-a-...

However, how might I introduce ordering between sibling nodes? I understand we can use ORDER_BY to sort nodes according to a particular property, but in this case it's important ordering acts as a list, e.g. we can insert, remove, and move around elements without needing to update a specific property on lots of elements simultaneously.

I've looked into using a linked list relationship, but it seems like that would be incompatible with apoc.convert.toTree(), as the linked list would return as a deeply nested tree.

How might I maintain both hierarchy and order in the graph? Is it possible to use UNWIND on elements of a linked list so they flatten before using apoc.convert.toTree()?

Thanks for your help and suggestions.

0 REPLIES 0
Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

All the sessions of the conference are now available online