LENGTH(collection) and COLECT WITH COUNT give different results

189 views
Skip to first unread message

Alexander

unread,
Jul 26, 2021, 5:45:55 AM7/26/21
to ArangoDB
Hello.
The query
RETURN {
    a: (FOR m IN collection COLLECT WITH COUNT INTO length RETURN length)[0],
    b: LENGTH( collection),
}
returns next result: [{ "a": 142058379, "b": 142050050 }].

How this could be? ArangoDB is deployed in single 3.7.6 instance.

Best regards,
Alexander.

Kerry Hormann

unread,
Jul 26, 2021, 2:41:59 PM7/26/21
to ArangoDB
Since your COLLECT function has no specific aggregate target, I would assume that it's doing some funky calculations with each document.  Whatever the process, it's giving you a count of unique values, probably across all attributes of all documents, not total items.

Try changing your COLLECT statement to this:
     ... COLLECT one = 1 WITH COUNT INTO ...

-- Kerry

Alexander

unread,
Jul 27, 2021, 7:30:29 AM7/27/21
to ArangoDB
Acording to https://www.arangodb.com/docs/stable/aql/examples-counting.html this two queries should be equivalent.

Best regards,
Alexander.
Reply all
Reply to author
Forward
0 new messages