sort¶
sort orders the rows. Name the columns, with - in front of a column for descending order.
Several columns : by last update, newest first, then by first name
GET /api/schema/admin/mysql8/inventory/customers?sort=-last_update,first_name
Body of the query APIs : a string or an object
{ "find": {}, "sort": "-last_update,first_name" }
{ "find": {}, "sort": { "last_update": -1, "first_name": 1 } }
Answer of ?sort=-customer_id
{
"success": true,
"statusCode": 200,
"data": [
{ "customer_id": 5, "first_name": "Eve", "last_name": "Page" },
{ "customer_id": 4, "first_name": "Eve", "last_name": "Mathly" },
{ "customer_id": 3, "first_name": "Mallory", "last_name": "Brown" }
]
}
- Spaces around the commas are fine :
-last_update, first_name. - On MongoDB a nested field sorts too :
sort=address.city. - Inside a
deepitem,sortorders the related rows of each parent. - Sorting a big table on a column without an index is slow ; Index Maker finds the queries which need one.