分页
所有 collection 的 find
查询都会自动进行分页处理。响应结果会包含与分页相关的顶层元数据,返回的文档则嵌套在 docs
数组中。
Find
响应属性:
属性 | 描述 |
---|---|
docs | collection 中的文档数组 |
totalDocs | collection 中可用的文档总数 |
limit | 查询参数 limit - 默认为 10 |
totalPages | 基于查询 limit 计算的总页数 |
page | 当前页码 |
pagingCounter | 当前页第一个文档的序号 |
hasPrevPage | true/false 表示是否存在上一页 |
hasNextPage | true/false 表示是否存在下一页 |
prevPage | 上一页页码,不存在则为 null |
nextPage | 下一页页码,不存在则为 null |
响应示例:
{
// 文档数组 // 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"
}
],
// 元数据 // highlight-line
"totalDocs": 6,
"limit": 1,
"totalPages": 6,
"page": 1,
"pagingCounter": 1,
"hasPrevPage": false,
"hasNextPage": true,
"prevPage": null,
"nextPage": 2
}
分页控制
所有 Payload API 都支持以下分页控制参数。通过这些参数,你可以在应用中创建分页的文档列表:
控制参数 | 默认值 | 描述 |
---|---|---|
limit | 10 | 限制每页返回的文档数量 - 设置为 0 可显示所有文档,当 limit 为 0 时,我们会自动禁用分页以优化性能 |
pagination | true | 设置为 false 可禁用分页并返回所有文档 |
page | 1 | 获取指定页码的文档 |
在 Local API 中禁用分页
对于 Local API 中的 find
操作,你可以通过向 find
本地操作传递 pagination: false
来禁用分页,从而获取集合中的所有文档。