Can't count collections with more than 600 000 documents

Hi,

when I try to do Count(Documents(Collection("NAME"))) it works great, unless the collection has more than 600 000 documents, then it throws this kind of error:

Error: [
  {
    "code": "bad request",
    "description": "Transaction does too much compute: got 603203, limit: 600000"
  }
]

Am I doing something wrong ?

Thank you in advance

Sorry for the late response,

There is a limit to how much computation you can do within one transaction. Fauna is not an aggregation (OLAP) type of database but a distributed OLTP which means at this point aggregations are going to do quite some work behind the scenes. In this case, the Count results in an O(n) operation.

To count more documents you’ll have to start paginating and continue counting from within the application.

Count(Paginate(Documents(....), { size: 100000}))

The max pagesize is 100000 though so to count further you’ll have to go over at least 6 pages in this case. You will receive an ‘after’ cursor to do so. The warning in the docs actually mentions the O(n) nature of Count: Count | Fauna Documentation