Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to count number of elements with AQL?

Tags:

count

arangodb

I need to count elements that was in result of SQL query: db._query('FOR v in visitors FILTER v.ip == "127.0.0.1" return COUNT(v.guid) ')

This request is return my a length of every GUID, but I need to get total number of GUIDs for example: 2.

like image 717
Dmitry Bubnenkov Avatar asked May 06 '16 16:05

Dmitry Bubnenkov


2 Answers

You need to use the result of the query as input for the COUNT function, and then RETURN this result.

You can replace the RETURN value of the actual query by 1 for performance reasons:

RETURN COUNT(FOR v IN visitors FILTER v.ip == "127.0.0.1" RETURN 1)
like image 80
dothebart Avatar answered Nov 07 '22 11:11

dothebart


Version from 2022!

FOR m IN messages 
FILTER DATE_HOUR(m.date) == 3
COLLECT WITH COUNT INTO length
RETURN length
like image 44
Nikita Anshakov Avatar answered Nov 07 '22 13:11

Nikita Anshakov