4
votes

Many (all?) of ArangoDB's graph functions accept an "example" document. The documentation for the example parameter says:

{} : 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

In each of these cases (except the idString), it seems I am providing both a key and a value for Arango to match against.

Is there a way for me to create an example that would match any document that has a specific key (as long as the value is not null)?

Just for illustration, here I would like to get any neighboring vertex that has a key of "actor" and I don't care what the value of that key is (as long as it has one):

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

Is this possible in ArangoDB?

1

1 Answers

4
votes

I don't think this is possible to do at the moment, because in the examples you cannot specify wildcards.

As we recently added custom visitors options to several other graph functions, it would be straight forward to add this possibility for GRAPH_NEIGHBORS, too. The visitor would look like this then:

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

And the AQL query to get the neighbors of interest:

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

Not sure if this is the best option, but at least it would produce the desired result. If you think this is sensible just let us know so we can add this in 2.4.4