How to pass the custom "skip" value to the Local API Find operation to skip concrete N docs? #16196
-
|
According to the documentation here https://payloadcms.com/docs/local-api/overview#collection-find, to skip the first N items, we can use only the But, in my case, I need to skip a custom number of docs in the query. A simplified example could be a "News" page: But the next block below "Other recent news" should display 20 next news items as small blocks - only title and concatenated summary, skipping the first 5 news, as they already displayed in the previous block. So, in the "Other recent news" I should execute a query with params like "limit 20, skip 5", but Payload Local API doesn't allow this:
So, is there any solution for this issue? If not, maybe it's worth adding a new argument "skip" to the Payload Local API Find operation? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
|
Payload doesn't currently support an offset/skip parameter — pagination is page-based only. For your specific use case though, you could do something like this: That should work reliably as long as you're sorting by a stable field. |
Beta Was this translation helpful? Give feedback.
-
|
Payload doesn't support a const allNews = await payload.find({
collection: 'news',
limit: 25,
sort: '-publishedAt',
});
const featured = allNews.slice(0, 5);
const otherRecent = allNews.slice(5, 25);This avoids multiple DB hits and keeps pagination logic in your code. If you need more control or want to avoid loading everything at once, you could use the REST API directly with a custom |
Beta Was this translation helpful? Give feedback.
Payload doesn't support a
skipparam in the local API, so you'll need to work around it. The cleanest approach is to query all the data you need in one call, then split it in memory. For example:This avoids multiple DB hits and keeps pagination logic in your code. If you need more control or want to avoid loading everything at once, you could use the REST API directly with a custom
skipquery param, but that means bypassing the local API. Adding askipparam to the local API has been requested before, but it's no…