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
}
Harness the Power of Custom Visitors for AQL Graph Traversals
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.
Explaining AQL Queries in a Fancier Way: ArangoDB Tutorial
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.
ArangoDB AQL Optimization: Returning & Modifying in v2.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
ArangoDB Query Builder: Simplifying Database Queries
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…)
Enhanced AQL in ArangoDB 2.4: Boost Query Performance
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:
Tour Around the New AQL Query Optimizer | ArangoDB Blog
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.
Data Modeling: MongoDB vs ArangoDB | ArangoDB Blog
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…)
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 }
AQL: Query Documents and Graphs Easily | ArangoDB 2013
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.
Get the latest tutorials,
blog posts and news:
Thanks for subscribing! Please check your email for further instructions.