Check out v4 of the Fauna CLI
v4 of the Fauna CLI is now in beta. The new version introduces enhancements to the developer experience, including an improved authentication workflow. To get started, check out the CLI v4 quick start. |
set.count()
Get the number of elements in a Set.
Description
Gets the number of elements in the calling Set.
Eager loading
This method uses eager loading and requires a read of each document in the calling Set. For large Sets, this may result in poor performance and high costs.
Considerations
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 the collection’s
history_days
setting 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!