How can i receive a last inserted _key in ArangoDB with AQL query? I put the item in the collection, the following element must contain _key created element. How do I get this _key?
Update on this question: Since ArangoDB 2.4 it is possible to retrieve the just-inserted document (or documents) even with an AQL query.
With previous versions of ArangoDB 2.3, the syntax for a single document INSERT was:
INSERT { value: 1 } IN collection
with no way to retrieve the system attributes (_key
, _rev
etc.) for the just-inserted document. Since 2.4, the following is possible, too:
INSERT { value: 1 } IN collection LET result = NEW RETURN result
The above returns the created document, including the specified attributes (value
in the above case) and the system attributes.
It also works for multi-document inserts, e.g. the following query
FOR i IN 1..10
INSERT { value: i } IN collection
can be turned into
FOR i IN 1..10
INSERT { value: i } IN collection LET result = NEW RETURN result
to return all inserted documents.
Sadly it is not possible at the moment (2.3) to receive the last inserted _key
with an AQL query.
However you can use db.<collection>.save({ Hello : "World" }):
to retrieve the latest _key
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With