Using Custom Visitors in AQL Graph Traversals

Visitors by jan

Jan blogged about some recent extensions for the AQL graph traversal functionality in ArangoDB. These extensions allow invoking user-defined JavaScript code for filtering and results generation in AQL queries that contain traversals.

This should make AQL graph traversals much more powerful than before.

Additionally, AQL graph traversals get more configurable, allowing to write traversal functions with control-flow logic and complex filtering. As a side-effect, this change facilitates writing specialized traversal functions with much higher efficiency than the general-purpose, cover-all-cases default ones.

Continued here on J@ArangoDB’s blog

More info...

Explaining AQL queries the fancier way

I have been looking at many AQL queries during the last few weeks…

Looking back, I can say that the JSON query execution plans provided by the explain() method have provided me with a lot of useful information about how the AQL optimizer had transformed a given query. This has helped testing and improving the query optimizer a great deal.

However, the JSON output produced by explain() is so detailed that even for the simplest cases queries it will span multiple screens. This is far too much for quickly assessing what a query will be doing and how it will be executed.

I therefore quickly put together a function that provides a much more compact explain output. Its input parameter is a query string, which it will send to the ArangoDB server to have it explained.

But it doesn’t print a voluminous JSON object. This one is for developers with a full schedule.

Read more on Jan’s Blog

More info...

Returning results from modifying AQL operations (V 2.4)

ArangoDB provides many options for finding and modifying data. Though there are several more specialized operation, data-modification AQL queries are the most general solution in ArangoDB. They allow to find documents using arbitrary filter criteria, and to modify or remove the documents once found.

Read in Jan’s blog how INSERT, UPDATE, REMOVE and REPLACE operations can now return modified documents and allow to find, modify and return documents from the same AQL query. Read on

More info...

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…)

More info...

AQL Improvements for 2.4

While on a retreat in Belgium, we found some spare time to work on improvements for AQL. These will be shipped with ArangoDB version 2.4, and are already available in the devel version for testing from now on.

Here’s a short overview of the improvements:

Collect with count

A common use case in query languages is to count the number of documents returned by a query. The AQL solution for this has been to use the LENGTH function and a subquery:

RETURN LENGTH((
  FOR doc IN collection 
    FILTER doc.someAttribute == someValue
    RETURN doc
  ))

This is quite long and probably unintuitive for people which have used SQL for years.

We therefore now allow using the following alternative version:

Read more on Jan’s Blog

More info...

A Tour Around the New AQL Query Optimizer

The major new feature in ArangoDB 2.3 is the shiny new AQL query optimizer and executor. These parts of ArangoDB have been rewritten in 2.3 to make AQL much better for our end users.

Since one of the initial releases, ArangoDB has been shipped with AQL, the ArangoDB Query Language. AQL has since then been ArangoDB’s most versatile way of executing simple and also the not-so-simple queries.

I’ll start with an overview of query execution in previous versions of ArangoDB, and then explain the new engine and explain the differences.

Read more on Jan’s Blog

More info...

Modeling Data in MongoDB vs ArangoDB

MongoDB is a document DB whereas ArangoDB is a multi-model DB supporting documents, graphs and key/values within a single database. When it comes to data modeling and data querying, they pursue somewhat different approaches.


In a Nutshell: In MongoDB, data modeling is “aggregate-oriented”, avoiding relations and joins. On the other side, everybody has probably used relational databases which organize the data in tables with relations and try to avoid as much redundancy as possible. Both approaches have their pros and cons. ArangoDB is somewhat in-between: You can both model and query your data in a “relational way” but also in an “aggregate-oriented way”, depending on your use case. ArangoDB offers joins, nesting of sub-documents and multi-collection graphs. (more…)

More info...

Modifying AQL

ArangoDB comes with a powerful query language, called AQL. It combines all the different aspects in any easy-to-use query language. You can use joins as in SQL or graph queries as in Cypher. However, up to now it only supported read-queries.

FOR u IN users 
  FOR c IN cities 
    FILTER u.zip == c.zip 
    RETURN { 'name': u.name, 'city': c.name }

Allows you to join the name of city a persons lives in. If you want to follow the social graph and mix in the neighbors, simply add a graph query.

FOR u IN users
  FOR c IN cities
    FILTER u.zip == c.zip
    RETURN {
      'name': u.name,
      'city': c.name, 
      'knows': GRAPH_NEIGHBORS('social', u)[*].vertex.name
    }

(more…)

More info...

Querying documents and graphs in one database with AQL – easily

Note: The following article was originally written as an answer in ArangoDB google group. It may help other people to understand the scope of ArangoDB and/or AQL, so we posted it here as well.

AQL, the query language, provides access to the data which is stored inside collections. The collections contain documents, identified by unique keys.

(more…)

More info...

AQL: Querying a nosql database the elegant & comfortable way

Having a long history with relational databases and having worked for a lot of years with SQL some people find it a bit inconvenient querying nosql databases e.g. via REST. Others have rather complex data models and need nevertheless an elegant and convenient way for querying. And we all love clean and simple interfaces.

ArangoDB comes with a couple of options for querying the data, among offer it implements the "ArangoDB Query Language" (AQL).

AQL is a declarative query language for simple and also very complex queries. Unless like in other nosql databases you can also query across collections, aggregate results, do some geo location stuff and even iterate over graphs.

So if you like the comfort of SQL but also the freedom of a schema free database, AQL is for you.

If you are interested in learning more about the concepts of ArangoDB checkout Jan's talk and slides.

But let's stop beating around the bush and rather have a look at specific examples.

Find the 5 regions in state CA with the most inhabitants:

FOR u IN users                                               /* iterate over all documents in collection 'users' */
  FILTER u.contact.address.state == "CA"                     /* filter on state attribute */
  COLLECT region = u.contact.region INTO group               /* group by region attribute */
  SORT LENGTH(group) DESC                                    /* sort by number of matches found, descending */
  LIMIT 0, 5                                                 /* get top 5 */
  RETURN { "region" : region, "count" : LENGTH(group) }      /* return a projection */

Find the other top 5 hobbies of male users that also like running

FOR likes IN (                                               /* iterate over result of subquery */
  FOR u IN users                                             /* iterate over all users */
    FILTER u.gender == "male" && "running" IN u.likes        /* filter on gender & likes contains "running" */
    FOR value IN u.likes                                     /* iterate over user's individual like values */
      FILTER value != "running"                              /* filter out "running" here */
      RETURN value
)
COLLECT what = likes INTO group                              /* group by like name */
SORT LENGTH(group) DESC                                      /* sort by number of matches found, descending */
LIMIT 0, 5                                                   /* get top 5 */
RETURN { "what" : what, "count" : LENGTH(group) }            /* return a projection */

Find the 10 nearest larger airports around Cologne

FOR a IN NEAR(airports, 50.67, 6.9, 200, "distance")         /* iterate over proximity search result */
  FILTER a.type == "large_airport"                           /* filter on airport type */
  SORT a.distance ASC                                        /* sort by distance, ascending */
  LIMIT 0, 10                                                /* get top 10 */
  RETURN { "name" : a.name, "code" : a.iata_code, "country" : a.iso_country, "city" : a.municipality, "distance" : CONCAT(TO_STRING(CEIL(a.distance/1000)), ' km') }

Find some users with their friends.

FOR u IN users                                               /* iterate over all users */
  FILTER u.gender == "female"                                /* filter on gender */
  FILTER u.contact.address.state == "CA"                     /* filter on state */
  LIMIT 0, 5                                                 /* limit the result */
  FOR fr IN (FOR f IN friendships                            /* iterate over friends */
    FILTER f.user == u._id                                   /* of current user */
    RETURN f.friends                                         /* to get the list of friend ids */
  )
  LET friendnames = (
    FOR f IN fr                                              /* loop over list of friend ids */
      FOR u2 IN users                                        /* join with users collection again */
        FILTER u2._id == f                                   /* restrict on user with friend id */
        RETURN u2.name                                       /* return friend name */
  )
  RETURN { "user" : u.name, "friends" : friendnames }        /* return some merged data */
More info...

Get the latest tutorials,
blog posts and news: