home shape

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
  }    

Read on here

Ingo

Ingo Friepoertner

Ingo is dealing with all the good ideas from the ArangoDB community, customers and industry experts to improve the value provided by the company’s native multi-model approach. In former positions he worked as a product owner and tech consultant, building custom software solutions for large companies in various industries. Ingo holds a diploma in business informatics from FHDW University of Applied Sciences.

Leave a Comment





Get the latest tutorials, blog posts and news: