limit()

Mission

The .limit() modifier restricts the maximum number of documents returned by a query builder to optimize page load speeds.

The Payoff

By completing this module, you will understand how to limit document queries, write valid constraints, and utilize overwrite behaviors.

Estimated Time: 2 minutesModules: 2 Concepts

Define the target document threshold

Establish the maximum number of items (e.g. 5, 10, 50) you wish to return.

Chain limit modifier to your builder

Append .limit(count) to configure the limit settings before running .get().
Interactive Code Snippet
typescript
// Fetch only the top 5 documentsconst items = await sdk.collection("products")  .limit(5)  .get();
Input Constraints
The limit count **must be a positive integer** (greater than 0). If you pass a string, decimal, or negative integer, the SDK raises a validation exception before dispatching.
Overwrite Rule
Subsequent calls to `.limit()` overwrite any previously configured limit settings on the builder instance.

Verify positive integer values

Ensure the parameter is a whole number greater than 0. Negative numbers or decimals cause early validation errors.

Manage multiple limit modifiers

Recall that chaining .limit() multiple times overwrites previous values on the builder state.