Sort Order
On how to achieve sorted results
To get sorted results on find(), you can put sort
option as parameter. The following rules apply:
As String
This is the most simplest one: put the column name to sort on that column. E.g:
To sort on multiple columns, use comma (",") as separator. Like this:
What about sort direction? Easy peasy:
As Array
You can also put sort option as array, like these examples below:
For sort order, wrap it as object and make the column name as the key while the direction being its value:
You can also use MongoDB-like syntax for sort order: 1 for ascending, -1 for descending order. You may also mix and match any style above:
As Object
The preferred way to express sort order in Dab. Clean & expressive:
Last updated