# Entity Service API: Ordering & Pagination

The Entity Service API offers the ability to order and paginate results found with its findMany() method.

# Ordering

To order results returned by the Entity Service API, use the orderBy parameter. Results can be ordered based on a single or on multiple attribute(s) and can also use relational ordering.

# Single

To order results by a single field, just pass it to the orderBy parameter:

  • either as a string to sort with the default ascending order
  • or as an object to define both the field name and the order (i.e. 'asc' for ascending order or 'desc' for descending order)
strapi.entityService('api::article.article').findMany({
  orderBy: 'id',
});

// single with direction
strapi.entityService('api::article.article').findMany({
  orderBy: { id: 'desc' },
});

# Multiple

To order results by multiple fields, pass the fields as an array to the orderBy parameter:

  • either as an array of strings to sort multiple fields using the default ascending order
  • or as an array of objects to define both the field name and the order (i.e. 'asc' for ascending order or 'desc' for descending order)
strapi.entityService('api::article.article').findMany({
  orderBy: ['publishDate', 'name'],
});

// multiple with direction
strapi.entityService('api::article.article').findMany({
  orderBy: [{ title: 'asc' }, { publishedAt: 'desc' }],
});

# Relational ordering

Fields can also be sorted based on fields from relations:

strapi.entityService('api::article.article').findMany({
  orderBy: {
    author: {
      name: 'asc',
    },
  },
});

# Pagination

To paginate results returned by the Entity Service API, use the start and limit parameters:

strapi.entityService('api::article.article').findMany({
  start: 10,
  limit: 15,
});