set.count()
Get the number of values in a Set.
Description
The count()
method gets the number of values in the Set.
Because this method scans the full set, it returns an error if there are more than 16,000 documents in the set. This method can timeout for large sets under that limit.
A document update stores a new version of the document for which counter data is poorly suited for database storage.
If a frequently updated counter is essential, an event-sourcing technique is recommended to reduce database contention and reduce unnecessary database operations.
If the event sourcing pattern isn’t suitable, the following improvements might be considered:
-
Set a collection history_days field to a small value, with a zero value recommended. Document history continues to be collected, but is removed sooner than the default zero days.
-
Periodically, run a query to explicitly remove document history.
-
Instead of attempting to implement a real-time counter, consider storing countable documents as a cache and periodically analyzing cache contents to update a reporting document.
Is this article helpful?
Tell Fauna how the article can be improved:
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!