以我曲線圖中,用戶連接到許多項目,每個項目都被遞歸地分割成許多子項。由於我的項目有一個特定的順序,我考慮這兩個選項,我的數據模型:想法提高我AQL查詢
現在我想創建一個查詢檢索中的兩個級別定UserID。這AQL是我第一次嘗試:
for itemId in (for b in board filter b._from == @_from sort b.order return b._to)
for item1 in (for t in item filter t._id == itemId return keep(t, '_id', 'title'))
return merge(item1, {board: (
for itemId2 in (for b in board filter b._from == item1._id sort b.order return b._to)
for t in item filter t._id == itemId2 return keep(t, '_id', 'title')
)})
的查詢工作,它輸出這樣的結果:
[
{
"title": "item 1",
"_id": "item/41260117498",
"board": [
{
"title": "item 4",
"_id": "item/42205736442"
},
{
"title": "item 5",
"_id": "item/42208423418"
}
]
},
{
"title": "item 2",
"_id": "item/41260772858",
"board": []
},
{
"title": "item 3",
"_id": "item/41883233786",
"board": []
}
]
這很好,但我覺得我的查詢是這樣一個簡單的穿越不必要的複雜性。請有人幫助我創造一個更好的嗎?