Dynamic Attribute Names in AQL: ArangoDB Techniques
On our mailing list, there is quite often the question whether attribute names in objects returned from AQL queries can be made dynamic. Jan discusses in his blog how such dynamic attribute names could be expressed and shows the current implementation that comes with ArangoDB 2.5 – adapting an ES6 proposal that might bring robust dynamic variable names to JavaScript as well.
In ArangoDB 2.5 you will be able to use dynamic variable names as follows:
FOR doc IN collection
LET type = doc.type;
RETURN { [type] : doc.value }
Functions are allowed as well:
FOR i IN 1..3
RETURN {
[ CONCAT('test', i) ] : i
}
Get the latest tutorials, blog posts and news: