What this is about
order in parameter sets the order of the matches. It is a list of criteria:
"order": [
{ "field": "active", "order": "ASC" },
{ "field": "amount", "order": "DESC" }
]
| Key | Meaning |
|---|---|
field | the field, also as a path like company.companyname |
order | ASC ascending (A → Z, 1 → 9, old → new), DESC descending, NONE do not sort |
Sorting in stages
Example data and order as above:
| label | active | amount |
|---|---|---|
| Alpha | true | 5 |
| Beta | false | 10 |
| Gamma | true | 15 |
flowchart LR
A["Stage 1: active ASC<br/>false before true"] --> B["Beta (false)"]
A --> C["Alpha, Gamma (true)"]
C --> D["Stage 2: amount DESC<br/>on a tie"]
D --> E["Gamma (15), Alpha (5)"]
Result: Beta, Gamma, Alpha.
All variants
When: one column, one direction
[{ "field": "amount", "order": "DESC" }] returns Gamma, Beta, Alpha.
Result: Sorted by one field.
When: Ties should be resolved in a stable way.
Add more criteria. A unique field like id or _createdOn works well as the last criterion. Then the order is always the same.
Result: An order without randomness.
When: A user interface turns off sorting for a column but still sends the criterion.
{ "field": "amount", "order": "NONE" } is skipped.
Result: As if the criterion were not there.
When: { "field": "amount" } or { "order": "ASC" }
An incomplete criterion is skipped, without an error.
Result: As if the criterion were not there.
When: Sorting by a field of a referenced object: { "field": "company.companyname", "order": "ASC" }.
Only objects that have this relation appear. Employees without a company are missing from data, but totalCount counts them. See Filtering and sorting across relations.
Result: Sorted by the company name.
When: order is missing or empty.
The database returns the matches in an order it picks itself. This order can change between two calls.
Result: Not defined. When paging, objects can appear twice or be missing.
When: { "field": "nope", "order": "ASC" } or { "field": "company.nope", "order": "ASC" }
-
1CDMSlooks for the field in the model
-
2CDMS→Clientnot found → 400
wrong-order-element-exception
Result: 400. Unlike a wrong filter, a wrong sort field is not silently ignored.
Decision table
| field | order | Result |
|---|---|---|
| present | ASC / DESC | is applied |
| present | NONE | skipped |
| missing | – | skipped |
| – | missing | skipped |
| unknown | ASC / DESC | 400 wrong-order-element-exception |
| – | lower case, e.g. asc | 400 invalid-value|parameter.order[0].order |