Skip to main content
Pagination allows you to retrieve large result sets in manageable chunks, improving performance and user experience.

Overview

Use pagination to retrieve records in pages:

Page-Based Pagination

Use page() for page-based pagination:

Page Parameters

  • page number: 1-based index (first page is 1)
  • per page: Number of items per page

Manual Pagination

Use limit() and skip() for manual offset pagination:

Manual Pagination Parameters

  • skip: Number of records to skip (offset)
  • limit: Maximum number of records to return

Pagination Response

The pagination response includes metadata:

Calculating Total Pages

Calculate the total number of pages:

Building a Paginator

Create a reusable pagination helper:

Combining with Filtering and Sorting

Combine pagination with filtering and sorting:
The total count reflects all matching records, not just the current page.

Infinite Scroll

Implement infinite scroll pagination:

React Example

Create a paginated list component:

Cursor-Based Pagination

For large or frequently-changing datasets, cursor-based pagination provides consistent results without skipping or duplicating records.

Forward Pagination

Backward Pagination

Use cursor_before to paginate backwards:

When to Use Cursor vs Offset

To get the total count with cursor pagination, pass include_count: true in your query parameters.

Performance Best Practices

1. Use Appropriate Page Sizes

Choose page sizes based on your use case:

2. Filter Before Pagination

Reduce the result set before paginating:

3. Cache Pagination Metadata

Store total count and page metadata:

Complete Example

Reference

page(pageNum, perPage?)

Set page number and size. Parameters:
  • pageNum (number) - Page number (1-based)
  • perPage (number) - Items per page (default: 30)
Returns: QueryBuilder<T>

limit(count)

Set maximum records (manual pagination). Parameters:
  • count (number) - Maximum records to return
Returns: QueryBuilder<T>

skip(count)

Set records to skip (manual pagination). Parameters:
  • count (number) - Number of records to skip
Returns: QueryBuilder<T>

Next Steps