简体   繁体   中英

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)..eg, 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 (ie Z).

Any help please?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM