Queries without collections

AQL queries typically access one or more collections to read from documents or to modify them. Queries don’t necessarily have to involve collections however. Below are a few examples of that.

Following is a query that returns a string value. The result string is contained in an array because the result of every valid query is an array:

RETURN "this will be returned"
Show query results
Hide query results
[
  "this will be returned"
]

You may use variables, call functions and return arbitrarily structured results:

LET array = [1, 2, 3, 4]
RETURN { array, sum: SUM(array) }
Show query results
Hide query results
[
  {
    "array": [
      1,
      2,
      3,
      4
    ],
    "sum": 10
  }
]

Language constructs such as the FOR loop can be used too. Below query creates the Cartesian product of two arrays and concatenates the value pairs:

FOR year IN [ 2011, 2012, 2013 ]
FOR quarter IN [ 1, 2, 3, 4 ]
  RETURN {
    year,
    quarter,
    formatted: CONCAT(quarter, " / ", year)
  }
Show query results
Hide query results
[
  {
    "year": 2011,
    "quarter": 1,
    "formatted": "1 / 2011"
  },
  {
    "year": 2011,
    "quarter": 2,
    "formatted": "2 / 2011"
  },
  {
    "year": 2011,
    "quarter": 3,
    "formatted": "3 / 2011"
  },
  {
    "year": 2011,
    "quarter": 4,
    "formatted": "4 / 2011"
  },
  {
    "year": 2012,
    "quarter": 1,
    "formatted": "1 / 2012"
  },
  {
    "year": 2012,
    "quarter": 2,
    "formatted": "2 / 2012"
  },
  {
    "year": 2012,
    "quarter": 3,
    "formatted": "3 / 2012"
  },
  {
    "year": 2012,
    "quarter": 4,
    "formatted": "4 / 2012"
  },
  {
    "year": 2013,
    "quarter": 1,
    "formatted": "1 / 2013"
  },
  {
    "year": 2013,
    "quarter": 2,
    "formatted": "2 / 2013"
  },
  {
    "year": 2013,
    "quarter": 3,
    "formatted": "3 / 2013"
  },
  {
    "year": 2013,
    "quarter": 4,
    "formatted": "4 / 2013"
  }
]