Search code examples
arangodbaql

How can I return all parents of a vertex in arango ql?


I'm trying to write an AQL query that returns all children of a vertex and that vertex itself.

For example I have this structure:

  A      B         C
  |      |         |
  D------          E     F

This is how my query looks:

for parent in collection
for child in outbound parent link
   RETURN{ parent, 
       child
    }

But it returns the results in the form

"child": D
"parent": A

"child": D
"parent":B

"child": E
"parent": C

The result I'm expecting from the query is like

"child": D
"parent": A, B

"child": E
"parent": C

"child": F
"parent": 

How can I amend my query to get the result?


Solution

  • After some messing about, I ended up creating a query suitable for my needs.

    FOR child in entity
         LET parents = (
                FOR p IN INBOUND child link
                RETURN {parentfp: p.fingerprint, parentTypeFp: p.typeFp})
                RETURN MERGE(\n" +
                {   
                  childFp: child.fingerprint,
                  childTypeFp: child.typeFp,
                  parents
                 })