Search.../

limit( )

Developer Preview

Limits the number of items the query returns.

Description

The limit() function defines the number of results a query returns in each page. Only one page of results is retrieved at a time. You can use the next() and prev() functions to navigate the pages of a query result.

Syntax

function limit(limit: number): PoliciesQueryBuilder

limit Parameters

NAME
TYPE
DESCRIPTION
limit
Optional
number

Number of items to return, which is also the pageSize of the results object.

Returns

Was this helpful?

Add a limit to a query

Copy Code
1const query = policies.queryPolicies.limit(10);
2
Create a query, add a limit, and run it

Copy Code
1import { policies } from 'wix-events.v2';
2
3export async function myQueryFunction() {
4 const results = await policies.queryPolicies().limit(10).find();
5
6 if (results.items.length > 0) {
7 const items = results.items;
8 const firstItem = items[0];
9 const pageSize = results.pageSize;
10 const hasNext = results.hasNext();
11 const hasPrev = results.hasPrev();
12 const length = results.length;
13 const query = results.query;
14
15 return items;
16 } else {
17 // Handle if no matching items found
18 }
19}
20