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.

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.


So far, so good. No media break in queries. However, if you wanted to change data in version 2.1, you needed to first query the data and then switch from AQL to one of the CRUD operations for the collection. Now it is possible to stay within AQL.

Updating documents

To update existing documents, we can either use the UPDATE or the REPLACE operation. UPDATE updates only the specified attributes in the found documents, and REPLACE completely replaces the found documents with the specified values.

We’ll start with an UPDATE query that rewrites the gender attribute in all documents:

To add new attributes to existing documents, we can also use an UPDATE query. The following query adds an attribute numberOfLogins for all users with status active:

Existing attributes can also be updated based on their previous value:

The above query will only work if there was already a numberOfLogins attribute present in the document. If it is unsure whether there is a numberOfLogins attribute in the document, the increase must be made conditional:

Updates of multiple attributes can be combined in a single query:

To completely replace existing documents, use the REPLACE operation. The following query replaces all documents in collection backup with the documents found in collection users. Only those documents will be replaced that are present in both collections. Documents are compared using their _key attributes:

The above query will fail if there are documents in collection users that are not in collection backup yet. In this case, the query would attempt to replace documents that do not exist. To make the query succeed for such case, use the ignoreErrors query option:

Removing documents

Removing documents can be achieved with the REMOVE operation. To remove all users within a certain age range, we can use the following query:

Creating documents

To create new documents, there is the INSERT operation. It can also be used to generate copies of existing documents from other collections, or to create synthetic documents (e.g. for testing purposes). The following query creates 1000 test users in collection users with some attributes set:

Copying data from one collection into another

To copy data from one collection into another, an INSERT operation can be used:

This will copy over all documents from collection users into collection backup. Note that both collections must already exist when the query is executed. The query might fail if backup already contains documents, as executing the insert might attempt to insert the same document again. This will trigger a unique key constraint violation. To make such copy operation work in all cases, the target collection can be emptied before using a REMOVE query.