Limit API Results & Increment "Views" on those

System Information
  • Strapi Version: 4.11.1:
  • Mac OS 12.6.6:

I’m trying to update my controller to return only 3 results with the lowest views, and then increment the views counter on each of those 3 entities. Would I use pagination to limit results? How can I modify a field (views) on each of the entities on the first page only? Any help is much appreciated!

I’ve made some headway and discovered I can either use API query parameters:


Or I can use the entityService:

let entries = await strapi.entityService.findMany('', {
        populate: '*',
        sort: [{ Cycles: 'asc' }, { publishedAt: 'desc' }],
        limit: 2,

I’d rather use the entity service, but it doesn’t return the entities in the same format as super.find(ctx), When I use super find most of the information is placed inside an attributes object, but when I use entityService the information is all placed on the root of the objects which breaks my consuming API. Is there a way to get entityService to output the same format as super.find()?

I noticed the core components used to be viewable in the documentation but now I’m not sure how I can examine the code from the core find() module.

You can using tranformResponse that should tranform it into the right format

Thank you so much! That’s exactly what I was looking for!

  • Reggie