Ponsietta
Ponsietta

Reputation: 319

Iterate only over attributes with array values in Arango

I know that in ArangoDB, you can use the below structure to iterate over all the attributes in a document:

FOR doc IN collection 
  LET attrs = ATTRIBUTES(doc)  

I would like to do something similar, however I would like to ignore attributes that don't have array values, that is I only want to iterate over key-values where the value is an array (not a string, object, etc.) Is it possible to filter the attributes out this way, and if so how?

Upvotes: 1

Views: 562

Answers (1)

CodeManX
CodeManX

Reputation: 11865

ATTRIBUTES() does not return all attributes in a document, but only the top-level attributes to be precise.

If you are interested in top-level attributes whose value is of type array, then you can do the following to get their attribute keys:

FOR doc IN collection
  LET attrs = (
    FOR att IN ATTRIBUTES(doc)
      FILTER IS_ARRAY(doc[att])
      RETURN att
  )
...

Upvotes: 4

Related Questions