orderBy property
The order to apply to the query results.
Callers can provide a full ordering, a partial ordering, or no ordering at all. While Firestore will always respect the provided order, the behavior for queries without a full ordering is different per database edition:
In Standard edition, Firestore guarantees a stable ordering through the following rules:
- The
order_byis required to reference all fields used with an inequality filter. - All fields that are required to be in the
order_bybut are not already present are appended in lexicographical ordering of the field name. - If an order on
__name__is not specified, it is appended by default.
Fields are appended with the same sort direction as the last order specified, or 'ASCENDING' if no order was specified. For example:
ORDER BY abecomesORDER BY a ASC, __name__ ASCORDER BY a DESCbecomesORDER BY a DESC, __name__ DESCWHERE a > 1becomesWHERE a > 1 ORDER BY a ASC, __name__ ASCWHERE __name__ > ... AND a > 1becomesWHERE __name__ > ... AND a > 1 ORDER BY a ASC, __name__ ASC
In Enterprise edition, Firestore does not guarantee a stable ordering.
Instead it will pick the most efficient ordering based on the indexes
available at the time of query execution. This will result in a different
ordering for queries that are otherwise identical. To ensure a stable
ordering, always include a unique field in the order_by clause, such as
__name__.
Implementation
final List<StructuredQuery_Order> orderBy;