2015-02-10 181 views
4

許多(所有?)ArangoDB的圖形函數接受一個「示例」文檔。對於例如參數的文件說:ArangoDB示例:用x的鍵匹配任何東西?

{} : Returns all possible vertices for this graph 
idString : Returns the vertex/edge with the id idString 
[idString1, idString2 ...] : Returns the vertices/edges with the ids matching the given strings. 
{key1 : value1, key2 : value2} : Returns the vertices/edges that match this example, which means that both have key1 and key2 with the corresponding attributes 
{key1.key2 : value1, key3 : value2} : It is possible to chain keys, which means that a document {key1 : {key2 : value1}, key3 : value2} would be a match 
[{key1 : value1}, {key2 : value2}] : Returns the vertices/edges that match one of the examples, which means that either key1 or key2 are set with the corresponding value 

在每種情況下(除了idString),看來我既提供密鑰和阿朗戈來匹配的值。

有沒有辦法讓我創建一個匹配任何具有特定鍵的文檔的示例(只要該值不爲空)?

爲了方便說明,在這裏我想獲得的是有「演員」的關鍵任何相鄰頂點和我不在乎什麼鍵的值(只要它有一個):

db._query('RETURN GRAPH_NEIGHBORS("movies", {movie: "Scarfies"}, {neighborExamples: [{actor: *}]})').toArray() 

這是可能在ArangoDB?

回答

4

我不認爲這是可能的,因爲在這些例子中你不能指定通配符。

由於我們最近爲其他幾個圖形函數添加了自定義訪問選項,因此可以直接添加GRAPH_NEIGHBORS的這種可能性。 訪客是這樣,那麼:

var func = function (config, result, vertex, path) { 
    if (vertex.hasOwnProperty('actor')) { 
    return vertex; 
    } 
}; 
require("org/arangodb/aql/functions").register("my::actorVisitor", func); 

而且AQL查詢來獲取感興趣的鄰居:

RETURN GRAPH_NEIGHBORS("movies", { movie: "Scarfies" }, { 
    visitorReturnsResult: true, 
    visitor: "my::actorVisitor" 
}) 

不知道這是否是最好的選擇,但它至少會產生預期的結果。如果你認爲這是明智的,那就讓我們知道,所以我們可以在2.4.4中添加這個。

+0

謝謝。我爲此打開了問題[1241](https://github.com/arangodb/arangodb/issues/1241)。 – mikewilliamson 2015-02-11 15:32:07