I have a collection "items" with data like this:
{"_key": "item1"}
{"_key": "item2", "parent": "item1"}
{"_key": "item3", "parent": "item2"}
{"_key": "item4", "parent": "item3"}
{"_key": "item5", "parent": "item4"}
{"_key": "item6", "parent": "item5"}
I want make query that return list like this: ["item5", "item4", "item3", "item2", "item1"]
Query that can make this is:
LET start_item = "item5"
FOR item1 in items
FILTER item1.parent == start_item
FOR item2 in items
FILTER item3.parent == item2.parent
FOR item3 in items
FILTER item4.parent == item3.parent
FOR item4 in items
FILTER item5.parent == item4.parent
FOR item5 in items
FILTER item6.parent == item5.parent
RETURN [item6.parent, item5.parent, item4.parent, item3.parent, item2.parent, item1.parent]
Is there way to make that query smaller? Something like "while" cycle with some condition like check "parent" exists?
This can be done using the Graph. But can make that without graph?