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: number): SessionQueryBuilder

limit Parameters

NAME
TYPE
DESCRIPTION
limit
number

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

Returns

A SessionQueryBuilder object representing the refined query.

Was this helpful?

Add a limit to a query

Copy Code
1let query = sessions.querySessions().limit(10);
Create a query, add a limit, and run it

Copy Code
1import { sessions } from "wix-bookings-backend";
2
3// ...
4
5sessions.querySessions()
6 .ge("end.timestamp", "2021-01-01T00:00:00.000Z")
7 .lt("start.timestamp", "2021-05-01T00:00:00.000Z")
8 .limit(10)
9 .find()
10 .then((results) => {
11 if (results.items.length > 0) {
12 const items = results.items;
13 const firstItem = items[0];
14 const totalCount = results.totalCount;
15 const pageSize = results.pageSize;
16 const currentPage = results.currentPage;
17 const totalPages = results.totalPages;
18 const hasNext = results.hasNext();
19 const hasPrev = results.hasPrev();
20 const length = results.length;
21 const query = results.query;
22 } else {
23 // handle case where no matching items found
24 }
25 })
26 .catch((error) => {
27 console.error(error);
28 });