Page Contents

An order filter specifies how to sort the results: ascending (ASC) or descending (DESC) based on the specified property.

Node.js API

Order by one property:

{order: 'propertyName <ASC|DESC>'}

Order by two or more properties:

{order: ['propertyName <ASC|DESC>', 'propertyName <ASC|DESC>',...]}

Where:

  • propertyName is the name of the property (field) to sort by.
  • <ASC|DESC> signifies either ASC for ascending order or DESC for descending order.

REST API

Order by one property:

?filter[order]=propertyName%20<ASC|DESC>

Order by two or more properties:

?filter[order][0]=propertyName <ASC|DESC>&filter[order][1]=propertyName <ASC|DESC>...

Where:

  • propertyName is the name of the property (field) to sort by.
  • <ASC|DESC> signifies either ASC for ascending order or DESC for descending order.

You can also use stringified JSON format in a REST query.

Examples

Return the three most expensive items, sorted by the price property:

Node.js API

await itemRepository.find({
  order: 'price DESC',
  limit: 3,
});

REST

/items?filter[order]=price%20DESC&filter[limit]=3

Or stringified JSON format:

/items?filter={"order":["price DESC"],"limit":3}