0
votes

If I run this query:

FOR i IN [
    my_collection[*].my_prop,
    my_other_collection[*].my_prop,
    ]
RETURN i

I get this error:

Query: AQL: collection not found: my_other_collection (while parsing)

It's true that 'my_other_collection' may not exist, but I still want the result from 'my_collection'. How can I make this error non-blocking ?

2

2 Answers

0
votes

A missing collection will cause an error and this can not be ignored or suppressed. There is also no concept of late-bound collections which would allow you to evaluate a string as collection reference at runtime. In short: this is not supported.

The question is why you would want to use such a pattern in the first place. I assume that both collections exists, then it will materialize the full array before returning anything, which is presumably memory intensive.

It would be much better to either keep the documents of both collections in a single collection (you may add an extra attribute type to distinguish between them) or to use an ArangoSearch view, so that you can search indexes attributes across collections.

0
votes

Beyond the two methods already mentioned in the previous answer (Arango search and single collection), you could do this in JavaScript , probably inside Foxx: Check if collections exist with db_collection(collection-name) Then build the query string using aql fragments and use union to merge the fragments to pull results from the different collections. Note that ,if the collections are large, you probably will want to filter that results instead of just pulling all the documents.