The Firebase JS SDK is now in BETA!
This EAP site is no longer maintained. See the official Firebase Documentation site for the latest documentation and information about the Firebase JS SDK.

Home > @firebase/firestore > / > orderBy

orderBy() function

Creates a QueryConstraint that sorts the query result by the specified field, optionally in descending order instead of ascending.

Signature:

export declare function orderBy(fieldPath: string | FieldPath, directionStr?: OrderByDirection): QueryConstraint;

Parameters

Parameter Type Description
fieldPath string | FieldPath The field to sort by.
directionStr OrderByDirection Optional direction to sort by ('asc' or 'desc'). If not specified, order will be ascending.

Returns:

QueryConstraint

The created Query.