Search.../

limit( )

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. The next() and prev() functions are used to navigate the pages of a query result.

By default, limit is set to 50.

The maximum value that limit() can accept is 1000.

Syntax

function limit(limit: string): ContactsQueryBuilder

limit Parameters

NAME
TYPE
DESCRIPTION
limit
string

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

Returns

A ContactsQueryBuilder object that contains the refined query.

Was this helpful?

Add a limit to a query

Copy Code
1const query = contacts.queryContacts().limit(10);
Create a query, add a limit, and run it

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { contacts } from 'wix-crm-backend';
3
4export const myQueryContactsFunction = webMethod(Permissions.Anyone, () => {
5
6 return contacts.queryContacts()
7 .limit(10)
8 .find()
9 .then((results) => {
10 if (results.items.length > 0) {
11 const items = results.items;
12 const firstItem = items[0];
13 const pageSize = results.pageSize;
14 const hasNext = results.hasNext();
15 const hasPrev = results.hasPrev();
16 const length = results.length;
17 const query = results.query;
18
19 return items;
20 } else {
21 // Handle case where no matching items found
22 }
23 })
24 .catch((error) => {
25 console.error(error);
26 })
27
28});