Convenient querying with AQL

AQL is a declarative query language similar to SQL. Other options are REST and querying by example.

Many nosql databases suffer from a rather limited query language compared to SQL, e.g. they do not support joins. This usually leads to lots of work in the application code where you have to stick everything together by yourself. ArangoDB does better.

ArangoDB does not support pure SQL, as SQL is too limited to cover the different data models in ArangoDB. For example, think of nested list structures inside a document, graph traversals, etc. There is no way to query such structures in standard SQL, and deviating from standard SQL does not make much sense. This is why we came up with AQL (ArangoDB Query Language). AQL supports joins, graph queries, list iteration, results filtering, results projection, sorting, variables, grouping, aggregate functions, unions, and intersections.

Accessing graph data

ArangoDB offers two ways to access graph data: “Path traversals” are small programs written in JavaScript – the general approach is very similar to Neo4j where you write the traversals in Java.
Programming gives you all the freedom to do whatever comes to your mind. That’s good. For standard use cases, programming might be too much effort. So ArangoDB’s query language (AQL, AQL manual) supports graphs as well. How does that look like and how does it differ from neo4j’s query language Cypher?

Let’s look at an example taken from the Neo4j website:

For example, here is a query which finds a user called John in an index and then traverses the graph looking for friends of John’s friends (though not his direct friends) before returning both John and any friends-of-friends that are found.

START john=node:node_auto_index(name = 'John') 
MATCH john-[:friend]->()-[:friend]->fof 
RETURN john, fof”

The same query looks in AQL like this:

FOR t IN TRAVERSAL(users, friends, "users/john", "outbound", 
{minDepth: 2}) RETURN t.vertex._key 

The result is: 
[ "maria", "steve" ]

Note: ArangoDB implements the Blueprints standard for graph databases.

Want to dig deeper? The AQL Tutorial has a couple of simple and more interesting examples–you can try them out live without installing anything.

Comments are closed.