limit method

Query<T> limit(
  1. int limit
)

Creates and returns a new Query that only returns the first matching documents.

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

  • limit The maximum number of items to return.
final query = firestore.collection('col').where('foo', WhereFilter.equal, 42);

query.limit(1).get().then((querySnapshot) {
  querySnapshot.forEach((documentSnapshot) {
    print('Found document at ${documentSnapshot.ref.path}');
  });
});

Implementation

Query<T> limit(int limit) {
  final options = _queryOptions.copyWith(
    limit: limit,
    limitType: LimitType.first,
  );
  return Query<T>._(
    firestore: firestore,
    queryOptions: options,
  );
}