Document Service API: Sorting and paginating results
The Document Service API offers the ability to sort and paginate query results.
Sortβ
To sort results returned by the Document Service API, include the sort
parameter with queries.
Sort on a single fieldβ
To order results returned by the Entity Service API, use the sort parameter. Results can be ordered based on a single or on multiple attribute(s) and can also use relational ordering.
Example request
const documents = await strapi.documents("api::article.article").findMany({
sort: "title:asc",
});
Example response
[
{
"id": "cjld2cjxh0000qzrmn831i7rn",
"title": "Test Article",
"slug": "test-article",
"body": "Test 1"
// ...
},
{
"id": "cjld2cjxh0001qzrm5q1j5q7m",
"title": "Test Article 2",
"slug": "test-article-2",
"body": "Test 2"
// ...
}
// ...
]
Sort on multiple fieldsβ
To sort on multiple fields, β¦
Example request
const documents = await strapi.documents("api::article.article").findMany({
sort: [{ title: "asc" }, { slug: "desc" }],
});
Example response
[
{
"id": "cjld2cjxh0000qzrmn831i7rn",
"title": "Test Article",
"slug": "test-article",
"body": "Test 1"
// ...
},
{
"id": "cjld2cjxh0001qzrm5q1j5q7m",
"title": "Test Article 2",
"slug": "test-article-2",
"body": "Test 2"
// ...
}
// ...
]
Paginationβ
To paginate resultsβ¦
Example request
const documents = await strapi.documents("api::article.article").findMany({
limit: 10,
start: 0,
});
Example response
[
{
"id": "cjld2cjxh0000qzrmn831i7rn",
"title": "Test Article",
"slug": "test-article",
"body": "Test 1"
// ...
},
{
"id": "cjld2cjxh0001qzrm5q1j5q7m",
"title": "Test Article 2",
"slug": "test-article-2",
"body": "Test 2"
// ...
}
// ... (8 more)
]