ArangoDB v3.8 reached End of Life (EOL) and is no longer supported.

This documentation is outdated. Please see the most recent version at docs.arangodb.com

Parsing queries

Clients can use ArangoDB to check if a given AQL query is syntactically valid. ArangoDB provides an HTTP REST API for this.

A query can also be parsed from the ArangoShell using ArangoStatement’s parse method. The parse method will throw an exception if the query is syntactically invalid. Otherwise, it will return the some information about the query.

The return value is an object with the collection names used in the query listed in the collections attribute, and all bind parameters listed in the bindVars attribute. Additionally, the internal representation of the query, the query’s abstract syntax tree, will be returned in the AST attribute of the result. Please note that the abstract syntax tree will be returned without any optimizations applied to it.

arangosh> var stmt = db._createStatement(
........> "FOR doc IN @@collection FILTER doc.foo == @bar RETURN doc");
arangosh> stmt.parse();
Show execution results
Hide execution results
{ 
  "bindVars" : [ 
    "bar", 
    "@collection" 
  ], 
  "collections" : [ ], 
  "ast" : [ 
    { 
      "type" : "root", 
      "subNodes" : [ 
        { 
          "type" : "for", 
          "subNodes" : [ 
            { 
              "type" : "variable", 
              "name" : "doc", 
              "id" : 0 
            }, 
            { 
              "type" : "datasource parameter", 
              "name" : "@collection" 
            }, 
            { 
              "type" : "no-op" 
            } 
          ] 
        }, 
        { 
          "type" : "filter", 
          "subNodes" : [ 
            { 
              "type" : "compare ==", 
              "excludesNull" : false, 
              "subNodes" : [ 
                { 
                  "type" : "attribute access", 
                  "name" : "foo", 
                  "subNodes" : [ 
                    { 
                      "type" : "reference", 
                      "name" : "doc", 
                      "id" : 0 
                    } 
                  ] 
                }, 
                { 
                  "type" : "parameter", 
                  "name" : "bar" 
                } 
              ] 
            } 
          ] 
        }, 
        { 
          "type" : "return", 
          "subNodes" : [ 
            { 
              "type" : "reference", 
              "name" : "doc", 
              "id" : 0 
            } 
          ] 
        } 
      ] 
    } 
  ] 
}