Search code examples
arangodbaql

how to get total number of ArangoDB AQL for paging


AQL support basic AQL for paging by LIMIT offset, count. But I need to get the total number of the query in order to know the total pages. How to get the total count of the query?

I know the LENGTH function to get the count of some collection, but maybe it doesn't suit for the following:

FOR v in 2 any 'Collection/id1' GRAPH 'graph-name' FILTER ... LIMIT 10 RETURN distinct v.

I want to get the total number, but I can't get it by RETURN distinct LENGTH(v)

I now can implement this in a ungraceful way:

LET nodeList=(FOR v IN 2 any 'Collection/id1' GRAPH 'graph-name' FILTER ... RETURN distinct v)
FOR v IN 2 any 'Collection/id1' GRAPH 'graph-name' FILTER ... limit 10 RETURN distinct {'nodes': v, 'total':LENGTH(nodeList)}

Is there any other good idea to get this?


Solution

  • I found this answer from the arangodb spring data project.

    AqlQueryOptions has fullCount() function, to return the total count of the query.

    and you can return the PageImpl which contains the query content and the pagination info.