Sami Mansour
Sami Mansour

Reputation: 1

Merging documents in Arangodb with AQL

Let's say I have a collection of (three) documents as in the example bellow:

doc1 {'X':'a', 'Y':'b', 'Z':'c'}
doc2 {'X':'m', 'Y':'n', 'Z':'c'}
doc3 {'X':'a', 'Y':'b', 'Z':'d'}

I would like to know the AQL query that allows me to somehow merge the identical documents in only one (identical according so some criteria). .e.g., let us say in my example I would like to merge the documents identical in attributes X and Y. The query should update the collection to become:

doc13 {'X':'a', 'Y':'b', 'Z':{'c', 'd'}}
doc2 {'X':'m', 'Y':'n', 'Z':'c'}

doc1 and doc3 should be removed, and replaced by a new document doc13 which is added to the collection and that regroups together the values of attributes other than X and Y (i.e. Z).

Any help please?

Upvotes: 0

Views: 154

Answers (1)

samuelthien
samuelthien

Reputation: 59

This answer might be irrelevant, but have you checkout the AQL user functions? You can write user function in javascript, then register this function in your database, and use this function in your AQL query, this is especially useful if you have a complicated query.

Upvotes: 0

Related Questions