Data-modification queries were enhanced in ArangoDB 2.4 to be able to also return the inserted, update or removed documents.
For example, the following statement inserted a few documents and also returned them with all their attributes:
1 2 3 4
The syntax for returning documents from data-modification queries only supported
the exact above format. Using a
LET clause was required, and the
was limited to returning the variable introduced by the
These syntax restrictions have been lifted in the
devel branch, which will become
release 2.6 eventually. The changes make returning values from data-modification
statements easier and also more flexible.
For example, specifying a
LET clause is not required anymore (though still fully
supported). Instead, the
RETURN clause can directly refer to the
making the query shorter and easier to write:
1 2 3
It is now also possible to return a projection instead of returning the entire documents. This can be used to reduce the amount of data returned by queries.
For example, the following query will return just the keys of the inserted documents:
1 2 3
Using OLD and NEW in the same query
In previous versions,
REPLACE statements could refer to either
OLD or the
NEW pseudo-value, but not to both. 2.6 lifts that restriction, so
now these queries can refer to both. One can utilize that to return both the previous
and the updated revision:
1 2 3
Calculations with OLD or NEW
It is now also possible to run additional calculations with
LET statements between
the data-modification part and the final
1 2 3 4
Still the following restrictions remain:
a data-modification operation can optionally be followed by any number of
LETclauses, and a final
RETURNclause. No other operations (e.g.
COLLECT) can be used after a data-modification operation
calculations following a data-modification operation must not access data in collections, so using functions such as
GRAPH_TRAVERSALetc. is disallowed.
The improvements are present in the
devel branch and can be tested in there from now on.
As usual, feedback is welcome!