SORT statement will force a sort of the array of already produced intermediate results in the current block.
SORT allows specifying one or multiple sort criteria and directions. The general syntax is:
Example query that is sorting by lastName (in ascending order), then firstName (in ascending order), then by id (in descending order):
Specifying the direction is optional. The default (implicit) direction for a sort expression is the ascending order. To explicitly specify the sort direction, the keywords
ASC (ascending) and
DESC can be used. Multiple sort criteria can be separated using commas. In this case the direction is specified for each expression separately. For example:
will first sort elements by lastName in ascending order and then by firstName in ascending order.
will first sort documents by lastName in descending order and then by firstName in ascending order.
will first sort elements by lastName in ascending order and then by firstName in descending order.