许多(全部?)ArangoDB的图形函数接受一个"示例"文献。示例参数的文档说:
{} : 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),似乎我为Arango提供了一个键和一个值来匹配。
有没有办法让我创建一个匹配任何具有特定键的文档的示例(只要该值不为null)?
仅仅是为了说明,这里我想得到任何一个具有" actor"键的邻居顶点。而且我不在乎该密钥的价值(只要它有一个):
db._query('RETURN GRAPH_NEIGHBORS("movies", {movie: "Scarfies"}, {neighborExamples: [{actor: *}]})').toArray()
这在ArangoDB中是否可行?
答案 0 :(得分: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
中添加