On building AQL Query Strings

I recently wrote two recipes about generating AQL query strings. They are contained in the ArangoDB cookbook by now:

After that, Github user tracker1 suggested in Github issue 1457 to take the ES6 template string variant even further, using a generator function for string building, and also using promises and ES7 async/await.

We can’t use ES7 async/await in ArangoDB at the moment due to lacking support in V8, but the suggested template string generator function seemed to be an obvious improvement that deserved inclusion in ArangoDB.

Basically, the suggestion is to use regular JavaScript variables/expressions in the template string and have them substituted safely.

With regular AQL bind parameters, a query looks like this:

This is immune to parameter injection, because the query string and the bind parameter value are passed in separately. But it’s not very ES6-y.


Posted in Query Language, Security | Leave a comment

AQL object literal simplification

ArangoDB’s devel branch recently saw a change that makes writing some AQL queries a bit simpler.

The change introduces an optional shorthand notation for object attributes in the style of ES6’s enhanced object literal notation.

For example, consider the following query that groups values by age attribute and counts the number of documents per distinct age value:

The object declaration in the last line of the query is somewhat redundant because one has to type identical attribute names and values:

In this case, the new shorthand notation simplifies the RETURN to:

In general, the shorthand notation can be used for all object literals when there is an attribute name that refers to a query variable of the same name.

It can also be mixed with the longer notation, e.g.:

Posted in Query Language | Leave a comment

Introducing RETURN DISTINCT for AQL queries

Last week saw the addition of the RETURN DISTINCT for AQL queries. This is a new shortcut syntax for making result sets unique.

For this purpose it can be used as an easier-to-memorize alternative for the already existing COLLECT statement. COLLECT is very flexible and can be used for multiple purposes, but it is syntactic overkill for making a result-set unique.

The new RETURN DISTINCT syntax makes queries easier to write and understand.

Here’s a non-scientific proof for this claim:

Compare the following queries, which both return each distinct age attribute value from the collection:



Posted in Query Language | Leave a comment

Diffing Two Documents in AQL

I just stumbled upon a comment in the ArangoDB blog asking how to create a diff of two documents with AQL.

Though there is no built-in AQL function to diff two documents, it is easily possible to build your own like in the following query.

Read more on how to diff two documents in AQL.

Posted in Query Language | 2 Comments

COLLECTing With a Hash Table

ArangoDB 2.6 will feature an alternative hash implementation of the AQL COLLECT operation. The new implementation can speed up some AQL queries that can not exploit indexes on the COLLECT group criteria.

This blog post provides a preview of the feature and shows some nice performance improvements. It also explains the COLLECT-related optimizer parts and how the optimizer will decide whether to use the new or the traditional implementation.


Posted in Performance, Query Language | 7 Comments

Creating Multi-Game Highscore Lists

I just came across a question about how to create highscore lists or leaderboards in ArangoDB, and how they would work when compared to Redis sorted sets.

This blog post tries to give an answer on the topic and also detailed instructions and queries for setting up highscore lists with ArangoDB. The additional section “Extensions” explains slightly more advanced highscore list use cases like multi-game highscore lists, joining data and maintaining a “last updated” date.

Posted in API, Documentation, Query Language | 3 Comments

Analyzing Git commits with ArangoDB

I often find myself searching for certain commits using git log and friends. While I really love the power and flexibility that come with the git and other Unix command-line tools, sometimes it can be more convenient to use a database to filter and aggregate commit data.

I gave it a quick try yesterday and imported the commit history of ArangoDB’s Git repository into ArangoDB and ran some queries on the data.

While the query results for our repository may not be interesting for everyone, I think it is still worth sharing what I did. Even though I didn’t try it, I think the overall procedure is applicable with any other Git repository.

More queries and how to convert and import Git commits in ArangoDB: Read on in Jan’s Blog

Posted in API, Query Language | Leave a comment

AQL Improvements in 2.5

Contained in 2.5 are some small but useful AQL language improvements plus several AQL optimizer improvements.

We are working on further AQL improvements for 2.5, but work is still ongoing. This post summarizes the improvements that are already completed and will be shipped with the initial ArangoDB 2.5 release.


Posted in Performance, Query Language | Leave a comment

YAOR – Yet Another Optimizer Rule

In the upcoming ArangoDB 2.5 (current devel branch) a new optimizer rule move-calculations-down was added. Jan showcases in his latest blog post how queries with calculations could benefit from this new optimiser rule.

Read in Jan’s blog how this rule could accelerate your queries

Posted in Performance, Query Language | Leave a comment

ArangoDB Query Builder

The most powerful way to query your data in ArangoDB is by using ArangoDB’s own query language, AQL. In the past using AQL in your JavaScript code sadly would often require writing long, unwieldy strings. This made writing complex queries difficult and could often lead to subtle syntax errors or mistakes.

The ArangoDB Query Builder (AQB) is a JavaScript node packaged module that provides a fluid API for writing AQL queries in plain JavaScript. And if you’re using ArangoDB 2.3, the aqb module is already available to your Foxx applications. (more…)

Posted in Foxx, Javascript, Query Language | Leave a comment