[英]How to use NEIGHBORS in AQL?
我是ArangoDB的新手,也是一位不斷增長的粉絲。 在許多事情中,我們需要將多對多關系轉換為圖形,並在那里進行有效查詢。 但是,我似乎無法重現NEIGHBORS中的行為,如“使用邊緣集合”中的食譜中所述 。
插入數據並運行后:
FOR b IN books RETURN { book: b, authors: NEIGHBORS(books, written, b._id, 'inbound') }
[
{
"book" : {
"_id" : "books/10519631898915",
"_key" : "10519631898915",
"_rev" : "10519631898915",
"title" : "The beauty of JOINS"
},
"authors" : [ ]
}
]
空作者名單! 我嘗試了這個:
FOR b IN books RETURN { book: b, authors: NEIGHBORS(authors, written, b._id, 'inbound') }
[
{
"book" : {
"_id" : "books/10519631898915",
"_key" : "10519631898915",
"_rev" : "10519631898915",
"title" : "The beauty of JOINS"
},
"authors" : [
"authors/10519474612515",
"authors/10519475792163"
]
}
]
返回_id列表。 這些都沒有返回我需要的食譜,這是預期的邊緣/頂點結構。 (所有已在2.6.9中測試過)
如何使用NEIGHBORS,如何實現我在純AQL中的目標? 是否有一個標准的NEIGHBORS(以及其他圖形AQL特性)文檔,其中包含每個參數的描述和類型以及返回值?
是的,我找到了一個解決方案:
FOR p IN PATHS(books, written, 'inbound')
RETURN p.destination
結果:
Warnings:
[1577], 'collection 'books' used as expression operand'
Result:
[
{
"_id": "books/10519631898915",
"_rev": "10519631898915",
"_key": "10519631898915",
"title": "The beauty of JOINS"
},
{
"_id": "authors/10519474612515",
"_rev": "10519474612515",
"_key": "10519474612515",
"name": {
"first": "John",
"last": "Doe"
}
},
{
"_id": "authors/10519475792163",
"_rev": "10519475792163",
"_key": "10519475792163",
"name": {
"first": "Maxima",
"last": "Musterfrau"
}
}
]
它至少得到目標頂點,但它似乎不對,因為我收到警告並且源頂點被包含為目標。 非常歡迎進一步的闡述和建議。
您是否嘗試過NEIGHBORS的includeData
選項?
FOR b IN books RETURN { book: b, authors: NEIGHBORS(authors, written, b._id, 'inbound', [], {includeData: true}) }
這在我的測試中起作用。 在大型數據集上,PATHS會更加高效(PATHS計算更多不相關的信息)
注意:空數組[]
用於定義僅應遵循的邊。 對於一個空數組,我們遵循所有邊,但您也可以遵循特殊邊緣fe {label: "written"}
而不是[]
。
更新(2017年):AQL 3.x不再支持NEIGHBORS
代替
NEIGHBORS(books, written, b._id, 'inbound')
你可以寫一個子查詢:
(FOR v IN 1..1 INBOUND b written RETURN v)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.