With Pagination you can limit the number of documents returned per page, and get a specific page of results. This is useful for creating paginated lists of documents within your application.
All paginated responses include documents nested within a docs array, and return top-level meta data related to pagination such as totalDocs, limit, totalPages, page, and more.
All Payload APIs support the pagination controls below. With them, you can create paginated lists of documents within your application:
Control | Default | Description |
|---|---|---|
| | Limits the number of documents returned per page. More details. |
| | Set to |
| | Get a specific page number. |
To specify pagination controls in the Local API, you can use the limit, page, and pagination options in your query:
With the REST API, you can use the pagination controls below as query strings:
All paginated responses include documents nested within a docs array, and return top-level meta data related to pagination.
The find operation includes the following properties in its response:
Property | Description |
|---|---|
| Array of documents in the collection |
| Total available documents within the collection |
| Limit query parameter - defaults to |
| Total pages available, based upon the |
| Current page number |
| |
| |
| |
| |
| |
Example response:
You can specify a limit to restrict the number of documents returned per page.
If you are querying for a specific document and can reliably expect only one document to match, you can set a limit of 1 (or another low number) to reduce the number of database lookups and improve performance.
For example, when querying a document by a unique field such as slug, you can set the limit to 1 since you know there will only be one document with that slug.
To do this, set the limit option in your query:
Disabling pagination can improve performance by reducing the overhead of pagination calculations and improve query speed.
For find operations within the Local API, you can disable pagination to retrieve all documents from a collection by passing pagination: false to the find local operation.
To do this, set pagination: false in your query: