AQL doesn't has the means to access collections dynamically, see: AQL: 
function to get collection by name? (#1138) 
<https://github.com/arangodb/arangodb/issues/1138>

You can look up documents dynamically however using DOCUMENT(handle).
This function has multiple signatures. For your use case, we can simply 
provide a handle like "entry1/2" (collection "entry1", document with _key 
"2").

FOR doc IN list
    UPDATE doc WITH { data: DOCUMENT(doc.entry).data } IN list

The query will iterate over all documents in the collection "list", fetch 
the content of the document with _id = doc.entry (e.g. "entry1/2"),
then extend the list document with an attribute key "data" and the 
attribute value of "data" from the dynamically loaded document (entry 
collections).

If there is no "entry" attribute, or the value doesn't refer to a document, 
then a "data" attribute is still added, but with a *null *value.
This could be prevented like this:

FOR doc IN list
    LET entry = DOCUMENT(doc.entry)
    UPDATE doc WITH (
        entry AND HAS(entry, "data")
        ? { data: entry.data }
        : {}
    ) IN list

But there is actually a better solution:

FOR doc IN list
    UPDATE doc WITH { data: DOCUMENT(doc.entry).data } IN list OPTIONS {
keepNull: false}

If the expression DOCUMENT(doc.entry).data returns *null*, it will be 
ignored in the update thanks to keepNull = false.
This will not affect any other existing attributes with a *null *value, 
only those updated (WITH clause) will be.

BTW: Instead of SPLIT(handle, "/")[0], you can use 
PARSE_IDENTIFIER(handle).collection (or .key for the _key part).

-- 
You received this message because you are subscribed to the Google Groups 
"ArangoDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to