orderBy method

Query<T> orderBy(
  1. Object path, {
  2. bool descending = false,
})

Creates and returns a new Query that's additionally sorted by the specified field, optionally in descending order instead of ascending.

This function returns a new (immutable) instance of the Query (rather than modify the existing instance) to impose the field mask.

  • fieldPath: The field to sort by.
  • descending (false by default) Whether to obtain documents in descending order.
final query = firestore.collection('col').where('foo', WhereFilter.equal, 42);

query.orderBy('foo', 'desc').get().then((querySnapshot) {
  querySnapshot.forEach((documentSnapshot) {
    print('Found document at ${documentSnapshot.ref.path}');
  });
});

Implementation

Query<T> orderBy(
  Object path, {
  bool descending = false,
}) {
  return orderByFieldPath(
    FieldPath.from(path),
    descending: descending,
  );
}