Search code examples
nosqlarangodbaql

Can't declare a variable in ArangoDB


I'm using ArangoDB 3.4.6-1 and would like to delete vertices with AQL (as stated here) in online console.

In the first step according to the tutorial you are supposed to save your Edges into a variable. In my case the statement looks like this:

LET edgeKeys =  (FOR v, e, p IN 1..100 INBOUND 'Node/N3' GRAPH 'graph' RETURN e._key)

The For itself without the brackets returns the correct result:

[
  "E3"
]

Yet, running the whole statement with the brackets just throws the following error:

Query: AQL: syntax error, unexpected end of query string near ')' at position 1:83 (while parsing)

I tried using a comparable command with other graphs or other returned values and objects, but always get the same error.

So far I wasn't able to find a proper solution online. The tutorial provides the following example code (copied 1:1):

LET edgeKeys = (FOR v, e IN 1..1 ANY 'persons/eve' GRAPH 'knows_graph' RETURN e._key)

And I'm getting exactly the same error, it's not even able to check the collections. What am I doing wrong?


Solution

  • Only defining a variable with LET is not a valid AQL statement.

    From the AQL Syntax documentation:

    An AQL query must either return a result (indicated by usage of the RETURN keyword) or execute a data-modification operation (indicated by usage of one of the keywords INSERT, UPDATE, REPLACE, REMOVE or UPSERT). The AQL parser will return an error if it detects more than one data-modification operation in the same query or if it cannot figure out if the query is meant to be a data retrieval or a modification operation.

    Using the full AQL block that is stated in the tutorial the execution works as expected since the query is executing a data-modification with REMOVE in this case. Just a RETURN operation inside the LET variable declaration is not sufficient to run an AQL query. When removing the LET operation the query works as well since in this case the AQL query directly returns the result.

    Complete AQL query:

    LET edgeKeys = (FOR v, e IN 1..1 ANY 'persons/eve' GRAPH 'knows_graph' RETURN e._key)
    LET r = (FOR key IN edgeKeys REMOVE key IN knows) 
    REMOVE 'eve' IN persons
    

    An additional RETURN also makes the query work:

    LET edgeKeys = (FOR v, e IN 1..1 ANY 'persons/eve' GRAPH 'knows_graph' RETURN e._key)
    RETURN edgeKeys