count()

Mission

The .count() method executes the query and returns the total number of matching records rather than fetching the documents themselves.

The Payoff

By completing this module, you will understand how to run server-side counts, save network bandwidth, and reduce processing overhead.

Estimated Time: 2 minutesModules: 2 Concepts

Assemble target search criteria

Establish any filter qualifiers using .where() chaining parameters.

Invoke the count request

Call .count() at the end of the query chain to fetch the total records integer.
Interactive Code Snippet
typescript
const totalActive = await sdk.collection("users")  .where("status", "=", "active")  .count();console.log("Total active users count:", totalActive);
High-Performance Counts
Using `.count()` is extremely lightweight. The database processes the filter conditions on the server and returns a simple integer, saving massive network bandwidth and reducing billing overhead compared to loading and counting large arrays of documents on the client-side.

Conserve system bandwidth

Load only a simple integer size key, bypassing massive JSON payload transfer queues.

Optimize database performance

Run count calculations directly inside the database engine, avoiding client-side array processing loops.