Query | Doclava
public class

Query

extends Object
java.lang.Object
   ↳ com.google.firebase.firestore.Query
Known Direct Subclasses

Class Overview

A Query which you can read or listen to. You can also construct refined Query objects by adding filters and ordering.

Subclassing Note: Firestore classes are not meant to be subclassed except for use in test mocks. Subclassing is not supported in production code and new SDK releases may break code that does so.

Summary

Nested Classes
enum Query.Direction An enum for the direction of a sort. 
Public Methods
ListenerRegistration addSnapshotListener(Activity activity, EventListener<QuerySnapshot> listener)
Starts listening to this query using an Activity-scoped listener.
ListenerRegistration addSnapshotListener(Activity activity, QueryListenOptions options, EventListener<QuerySnapshot> listener)
Starts listening to this query with the given options, using an Activity-scoped listener.
ListenerRegistration addSnapshotListener(Executor executor, EventListener<QuerySnapshot> listener)
Starts listening to this query.
ListenerRegistration addSnapshotListener(Executor executor, QueryListenOptions options, EventListener<QuerySnapshot> listener)
Starts listening to this query with the given options.
ListenerRegistration addSnapshotListener(QueryListenOptions options, EventListener<QuerySnapshot> listener)
Starts listening to this query with the given options.
ListenerRegistration addSnapshotListener(EventListener<QuerySnapshot> listener)
Starts listening to this query.
Query endAt(DocumentSnapshot snapshot)
Creates and returns a new Query that ends at the provided document (inclusive).
Query endAt(Object... fieldValues)
Creates and returns a new Query that ends at the provided fields relative to the order of the query.
Query endBefore(DocumentSnapshot snapshot)
Creates and returns a new Query that ends before the provided document (exclusive).
Query endBefore(Object... fieldValues)
Creates and returns a new Query that ends before the provided fields relative to the order of the query.
Task<QuerySnapshot> get()
Executes the query and returns the results as QuerySnapshot.
FirebaseFirestore getFirestore()
Gets the Firestore instance associated with this query.
Query limit(long limit)
Creates and returns a new Query that's additionally limited to only return up to the specified number of documents.
Query orderBy(String field, Query.Direction direction)
Creates and returns a new Query that's additionally sorted by the specified field, optionally in descending order instead of ascending.
Query orderBy(FieldPath fieldPath)
Creates and returns a new Query that's additionally sorted by the specified field.
Query orderBy(FieldPath fieldPath, Query.Direction direction)
Creates and returns a new Query that's additionally sorted by the specified field, optionally in descending order instead of ascending.
Query orderBy(String field)
Creates and returns a new Query that's additionally sorted by the specified field.
Query startAfter(Object... fieldValues)
Creates and returns a new Query that starts after the provided fields relative to the order of the query.
Query startAfter(DocumentSnapshot snapshot)
Creates and returns a new Query that starts after the provided document (exclusive).
Query startAt(Object... fieldValues)
Creates and returns a new Query that starts at the provided fields relative to the order of the query.
Query startAt(DocumentSnapshot snapshot)
Creates and returns a new Query that starts at the provided document (inclusive).
Query whereEqualTo(String field, Object value)
Creates and returns a new Query with the additional filter that documents must contain the specified field and the value should be equal to the specified value.
Query whereEqualTo(FieldPath fieldPath, Object value)
Creates and returns a new Query with the additional filter that documents must contain the specified field and the value should be equal to the specified value.
Query whereGreaterThan(FieldPath fieldPath, Object value)
Creates and returns a new Query with the additional filter that documents must contain the specified field and the value should be greater than the specified value.
Query whereGreaterThan(String field, Object value)
Creates and returns a new Query with the additional filter that documents must contain the specified field and the value should be greater than the specified value.
Query whereGreaterThanOrEqualTo(String field, Object value)
Creates and returns a new Query with the additional filter that documents must contain the specified field and the value should be greater than or equal to the specified value.
Query whereGreaterThanOrEqualTo(FieldPath fieldPath, Object value)
Creates and returns a new Query with the additional filter that documents must contain the specified field and the value should be greater than or equal to the specified value.
Query whereLessThan(String field, Object value)
Creates and returns a new Query with the additional filter that documents must contain the specified field and the value should be less than the specified value.
Query whereLessThan(FieldPath fieldPath, Object value)
Creates and returns a new Query with the additional filter that documents must contain the specified field and the value should be less than the specified value.
Query whereLessThanOrEqualTo(FieldPath fieldPath, Object value)
Creates and returns a new Query with the additional filter that documents must contain the specified field and the value should be less than or equal to the specified value.
Query whereLessThanOrEqualTo(String field, Object value)
Creates and returns a new Query with the additional filter that documents must contain the specified field and the value should be less than or equal to the specified value.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public ListenerRegistration addSnapshotListener (Activity activity, EventListener<QuerySnapshot> listener)

Starts listening to this query using an Activity-scoped listener.

The listener will be automatically removed during onStop().

Parameters
activity Activity:The activity to scope the listener to.

listener EventListener:The event listener that will be called with the snapshots.

Returns
ListenerRegistration A registration object that can be used to remove the listener.

public ListenerRegistration addSnapshotListener (Activity activity, QueryListenOptions options, EventListener<QuerySnapshot> listener)

Starts listening to this query with the given options, using an Activity-scoped listener.

The listener will be automatically removed during onStop().

Parameters
activity Activity:The activity to scope the listener to.

options QueryListenOptions:The options to use for this listen.

listener EventListener:The event listener that will be called with the snapshots.

Returns
ListenerRegistration A registration object that can be used to remove the listener.

public ListenerRegistration addSnapshotListener (Executor executor, EventListener<QuerySnapshot> listener)

Starts listening to this query.

Parameters
executor Executor:The executor to use to call the listener.

listener EventListener:The event listener that will be called with the snapshots.

Returns
ListenerRegistration A registration object that can be used to remove the listener.

public ListenerRegistration addSnapshotListener (Executor executor, QueryListenOptions options, EventListener<QuerySnapshot> listener)

Starts listening to this query with the given options.

Parameters
executor Executor:The executor to use to call the listener.

options QueryListenOptions:The options to use for this listen.

listener EventListener:The event listener that will be called with the snapshots.

Returns
ListenerRegistration A registration object that can be used to remove the listener.

public ListenerRegistration addSnapshotListener (QueryListenOptions options, EventListener<QuerySnapshot> listener)

Starts listening to this query with the given options.

Parameters
options QueryListenOptions:The options to use for this listen.

listener EventListener:The event listener that will be called with the snapshots.

Returns
ListenerRegistration A registration object that can be used to remove the listener.

public ListenerRegistration addSnapshotListener (EventListener<QuerySnapshot> listener)

Starts listening to this query.

Parameters
listener EventListener:The event listener that will be called with the snapshots.

Returns
ListenerRegistration A registration object that can be used to remove the listener.

public Query endAt (DocumentSnapshot snapshot)

Creates and returns a new Query that ends at the provided document (inclusive). The end position is relative to the order of the query. The document must contain all of the fields provided in the orderBy of this query.

Parameters
snapshot DocumentSnapshot:The snapshot of the document to end at.

Returns
Query The created Query.

public Query endAt (Object... fieldValues)

Creates and returns a new Query that ends at the provided fields relative to the order of the query. The order of the field values must match the order of the order by clauses of the query.

Parameters
fieldValues Object:The field values to end this query at, in order of the query's order by.

Returns
Query The created Query.

public Query endBefore (DocumentSnapshot snapshot)

Creates and returns a new Query that ends before the provided document (exclusive). The end position is relative to the order of the query. The document must contain all of the fields provided in the orderBy of this query.

Parameters
snapshot DocumentSnapshot:The snapshot of the document to end before.

Returns
Query The created Query.

public Query endBefore (Object... fieldValues)

Creates and returns a new Query that ends before the provided fields relative to the order of the query. The order of the field values must match the order of the order by clauses of the query.

Parameters
fieldValues Object:The field values to end this query before, in order of the query's order by.

Returns
Query The created Query.

public Task<QuerySnapshot> get ()

Executes the query and returns the results as QuerySnapshot.

Returns
Task<QuerySnapshot> A Task that will be resolved with the results of the Query.

public FirebaseFirestore getFirestore ()

Gets the Firestore instance associated with this query.

Returns
FirebaseFirestore

public Query limit (long limit)

Creates and returns a new Query that's additionally limited to only return up to the specified number of documents.

Parameters
limit long:The maximum number of items to return.

Returns
Query The created Query.

public Query orderBy (String field, Query.Direction direction)

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

Parameters
field String:The field to sort by.

direction Query.Direction:The direction to sort.

Returns
Query The created Query.

public Query orderBy (FieldPath fieldPath)

Creates and returns a new Query that's additionally sorted by the specified field.

Parameters
fieldPath FieldPath:The field to sort by.

Returns
Query The created Query.

public Query orderBy (FieldPath fieldPath, Query.Direction direction)

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

Parameters
fieldPath FieldPath:The field to sort by.

direction Query.Direction:The direction to sort.

Returns
Query The created Query.

public Query orderBy (String field)

Creates and returns a new Query that's additionally sorted by the specified field.

Parameters
field String:The field to sort by.

Returns
Query The created Query.

public Query startAfter (Object... fieldValues)

Creates and returns a new Query that starts after the provided fields relative to the order of the query. The order of the field values must match the order of the order by clauses of the query.

Parameters
fieldValues Object:The field values to start this query after, in order of the query's order by.

Returns
Query The created Query.

public Query startAfter (DocumentSnapshot snapshot)

Creates and returns a new Query that starts after the provided document (exclusive). The starting position is relative to the order of the query. The document must contain all of the fields provided in the orderBy of this query.

Parameters
snapshot DocumentSnapshot:The snapshot of the document to start after.

Returns
Query The created Query.

public Query startAt (Object... fieldValues)

Creates and returns a new Query that starts at the provided fields relative to the order of the query. The order of the field values must match the order of the order by clauses of the query.

Parameters
fieldValues Object:The field values to start this query at, in order of the query's order by.

Returns
Query The created Query.

public Query startAt (DocumentSnapshot snapshot)

Creates and returns a new Query that starts at the provided document (inclusive). The starting position is relative to the order of the query. The document must contain all of the fields provided in the orderBy of this query.

Parameters
snapshot DocumentSnapshot:The snapshot of the document to start at.

Returns
Query The created Query.

public Query whereEqualTo (String field, Object value)

Creates and returns a new Query with the additional filter that documents must contain the specified field and the value should be equal to the specified value.

Parameters
field String:The name of the field to compare

value Object:The value for comparison

Returns
Query The created Query.

public Query whereEqualTo (FieldPath fieldPath, Object value)

Creates and returns a new Query with the additional filter that documents must contain the specified field and the value should be equal to the specified value.

Parameters
fieldPath FieldPath:The path of the field to compare

value Object:The value for comparison

Returns
Query The created Query.

public Query whereGreaterThan (FieldPath fieldPath, Object value)

Creates and returns a new Query with the additional filter that documents must contain the specified field and the value should be greater than the specified value.

Parameters
fieldPath FieldPath:The path of the field to compare

value Object:The value for comparison

Returns
Query The created Query.

public Query whereGreaterThan (String field, Object value)

Creates and returns a new Query with the additional filter that documents must contain the specified field and the value should be greater than the specified value.

Parameters
field String:The name of the field to compare

value Object:The value for comparison

Returns
Query The created Query.

public Query whereGreaterThanOrEqualTo (String field, Object value)

Creates and returns a new Query with the additional filter that documents must contain the specified field and the value should be greater than or equal to the specified value.

Parameters
field String:The name of the field to compare

value Object:The value for comparison

Returns
Query The created Query.

public Query whereGreaterThanOrEqualTo (FieldPath fieldPath, Object value)

Creates and returns a new Query with the additional filter that documents must contain the specified field and the value should be greater than or equal to the specified value.

Parameters
fieldPath FieldPath:The path of the field to compare

value Object:The value for comparison

Returns
Query The created Query.

public Query whereLessThan (String field, Object value)

Creates and returns a new Query with the additional filter that documents must contain the specified field and the value should be less than the specified value.

Parameters
field String:The name of the field to compare

value Object:The value for comparison

Returns
Query The created Query.

public Query whereLessThan (FieldPath fieldPath, Object value)

Creates and returns a new Query with the additional filter that documents must contain the specified field and the value should be less than the specified value.

Parameters
fieldPath FieldPath:The path of the field to compare

value Object:The value for comparison

Returns
Query The created Query.

public Query whereLessThanOrEqualTo (FieldPath fieldPath, Object value)

Creates and returns a new Query with the additional filter that documents must contain the specified field and the value should be less than or equal to the specified value.

Parameters
fieldPath FieldPath:The path of the field to compare

value Object:The value for comparison

Returns
Query The created Query.

public Query whereLessThanOrEqualTo (String field, Object value)

Creates and returns a new Query with the additional filter that documents must contain the specified field and the value should be less than or equal to the specified value.

Parameters
field String:The name of the field to compare

value Object:The value for comparison

Returns
Query The created Query.