2015-02-10 38 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

相关问题