3

I have a list of documents and would like to combine them into a single document. The documentation for Arango says you can merge two documents like this:

arangosh [EC]> db._query('RETURN MERGE({foo: "bar"}, {fizz: "buzz"})', {}).toArray()
[ 
  { 
    "foo" : "bar", 
    "fizz" : "buzz" 
  } 
]

But the merge function does not accept lists:

arangosh [EC]> db._query('RETURN MERGE([{foo: "bar"}, {fizz: "buzz"}])', {}).toArray()
JavaScript exception in file '/usr/share/arangodb/js/client/modules/org/arangodb/arangosh.js' at 104,11: [ArangoError 1541: invalid number of arguments for function 'MERGE()', expected number of arguments: minimum: 2, maximum: 65536 (while parsing)]
!    throw new ArangoError(requestResult);

How do I combine documents together in AQL?

mikewilliamson
  • 24,303
  • 17
  • 59
  • 90

1 Answers1

1

I think it can be done using APPLY().

APPLY() takes a function name as its first parameter. The second parameter is an array of parameters for this function. It will then call the function and make the array elements individual call parameters:

RETURN APPLY("merge", [{foo: "bar"}, {fizz: "buzz"})
stj
  • 9,037
  • 19
  • 33