Mixin: CollectionOrdering

CollectionOrdering

This mixin grants sorting capabilities to a collection statement instance via composition.

Methods


sort( [sortExprStrList])

Establishes the order of one or more specific fields in the result set. This method does not cause the statement to be executed but changes the statement boundaries, which means that if it has been prepared before, it needs to be re-prepared.
Parameters:
Name Type Argument Description
sortExprStrList SortExprStrList <optional>
<repeatable>
One or more expressions establishing the order on which the given fields are sorted.
Returns:
The instance of the statement itself following a fluent API convention.
Type
CollectionOrdering
Example
// arguments as columns (and direction) to sort
const query = collection.find().sort('foo asc', 'bar desc')

// array of columns (and direction) to sort
const query = collection.find().sort(['foo asc', 'bar desc'])