66 lines
2.5 KiB
Plaintext
66 lines
2.5 KiB
Plaintext
---
|
|
title: Pagination
|
|
label: Pagination
|
|
order: 40
|
|
desc: Payload queries are equipped with automatic pagination so you create paginated lists of documents within your app.
|
|
keywords: query, documents, pagination, documentation, Content Management System, cms, headless, javascript, node, react, nextjs
|
|
---
|
|
|
|
All collection `find` queries are paginated automatically. Responses are returned with top-level meta data related to pagination, and returned documents are nested within a `docs` array.
|
|
|
|
**`Find` response properties:**
|
|
|
|
| Property | Description |
|
|
| ------------- | --------------------------------------------------------- |
|
|
| docs | Array of documents in the collection |
|
|
| totalDocs | Total available documents within the collection |
|
|
| limit | Limit query parameter - defaults to `10` |
|
|
| totalPages | Total pages available, based upon the `limit` queried for |
|
|
| page | Current page number |
|
|
| pagingCounter | `number` of the first doc on the current page |
|
|
| hasPrevPage | `true/false` if previous page exists |
|
|
| hasNextPage | `true/false` if next page exists |
|
|
| prevPage | `number` of previous page, `null` if it doesn't exist |
|
|
| nextPage | `number` of next page, `null` if it doesn't exist |
|
|
|
|
**Example response:**
|
|
|
|
```json
|
|
{
|
|
// Document Array // highlight-line
|
|
"docs": [
|
|
{
|
|
"title": "Page Title",
|
|
"description": "Some description text",
|
|
"priority": 1,
|
|
"createdAt": "2020-10-17T01:19:29.858Z",
|
|
"updatedAt": "2020-10-17T01:19:29.858Z",
|
|
"id": "5f8a46a1dd05db75c3c64760"
|
|
}
|
|
],
|
|
// Metadata // highlight-line
|
|
"totalDocs": 6,
|
|
"limit": 1,
|
|
"totalPages": 6,
|
|
"page": 1,
|
|
"pagingCounter": 1,
|
|
"hasPrevPage": false,
|
|
"hasNextPage": true,
|
|
"prevPage": null,
|
|
"nextPage": 2
|
|
}
|
|
```
|
|
|
|
## Pagination controls
|
|
|
|
All Payload APIs support the pagination controls below. With them, you can create paginated lists of documents within your application:
|
|
|
|
| Control | Description |
|
|
| ------- | --------------------------------------- |
|
|
| `limit` | Limits the number of documents returned |
|
|
| `page` | Get a specific page number |
|
|
|
|
### Disabling pagination within Local API
|
|
|
|
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.
|