Easily reorder-able ordered list

Hi β€” working on my first project with Neo4j and am looking for opinions about the best way to model something.

So the idea is there are (c:Collection) nodes and (d:Document) nodes. The (c:Collection) nodes can -[r:CONTAINS]-> a (d:Document).

The order of the documents contained by the collection is very important, and the order of the documents needs to be easy to change so I need to figure out the best way to store order values.

Option 1: It seems like the most natural way is to store the order is as a property of the relationship e.g. (c:Collection) -[r:CONTAINS {position: $position}]-> (d:Document), but I’m totally unclear on the best way to reorder the documents without having to make a database query to edit each relationship every time the order is changed.

Option 2: Alternatively, I could just store the order in an array as a property of the parent collection, which I could then revise with one query, but that feels non-idiomatic and clumsy.

Is there a way to take a map of key/values (id: position) as a param and use that to set the position property of each -[:CONTAINS]-> relationship for a collection without having to make a bunch of queries? Or another way to make option 1 work smoothly?

Or should I just use #2, or some other approach?

Thanks for any thoughts!

Would this work for your example?

1 Like

Hi, the option given by @kathryn.moore is the best solution if each document only belongs to one collection. Otherwise, the best solution is the #2 for me because query building is easier and the performance is better.

Thanks

1 Like

Chaining them all together is an interesting idea, but it seems like doing reorders might still require a bunch of writes? Maybe I'll just go with the #2 option of storing the order as an array in the parent collection, to keep the queries a little simpler.

Thanks!