Query

public class Query

Known direct subclasses
CollectionReference

A CollectionReference can be used for adding documents, getting document references, and querying for documents (using the methods inherited from Query).


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

Subclassing Note: Cloud 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 types

public enum Query.Direction

An enum for the direction of a sort.

Public fields

final FirebaseFirestore

Public methods

@NonNull ListenerRegistration

Starts listening to this query.

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

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

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

Starts listening to this query.

@NonNull ListenerRegistration
addSnapshotListener(
    @NonNull MetadataChanges metadataChanges,
    @NonNull EventListener<QuerySnapshot> listener
)

Starts listening to this query with the given options.

@NonNull ListenerRegistration
addSnapshotListener(
    @NonNull Activity activity,
    @NonNull MetadataChanges metadataChanges,
    @NonNull EventListener<QuerySnapshot> listener
)

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

@NonNull ListenerRegistration
addSnapshotListener(
    @NonNull Executor executor,
    @NonNull MetadataChanges metadataChanges,
    @NonNull EventListener<QuerySnapshot> listener
)

Starts listening to this query with the given options.

@NonNull AggregateQuery
aggregate(
    @NonNull AggregateField aggregateField,
    @NonNull AggregateField[] aggregateFields
)

Calculates the specified aggregations over the documents in the result set of the given query without actually downloading the documents.

@NonNull AggregateQuery

Returns a query that counts the documents in the result set of this query.

@NonNull Query
endAt(Object[] fieldValues)

Creates and returns a new Query that ends at the provided fields relative to the order of the query.

@NonNull Query

Creates and returns a new Query that ends at the provided document (inclusive).

@NonNull Query
endBefore(Object[] fieldValues)

Creates and returns a new Query that ends before the provided fields relative to the order of the query.

@NonNull Query

Creates and returns a new Query that ends before the provided document (exclusive).

boolean
@NonNull Task<QuerySnapshot>
get()

Executes the query and returns the results as a QuerySnapshot.

@NonNull Task<QuerySnapshot>
get(@NonNull Source source)

Executes the query and returns the results as a QuerySnapshot.

@NonNull FirebaseFirestore

Gets the Cloud Firestore instance associated with this query.

int
@NonNull Query
limit(long limit)

Creates and returns a new Query that only returns the first matching documents up to the specified number.

@NonNull Query
limitToLast(long limit)

Creates and returns a new Query that only returns the last matching documents up to the specified number.

@NonNull Query

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

@NonNull Query

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

@NonNull Query

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

@NonNull Query
orderBy(@NonNull FieldPath fieldPath, @NonNull Query.Direction direction)

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

@NonNull Query
startAfter(Object[] fieldValues)

Creates and returns a new Query that starts after the provided fields relative to the order of the query.

@NonNull Query

Creates and returns a new Query that starts after the provided document (exclusive).

@NonNull Query
startAt(Object[] fieldValues)

Creates and returns a new Query that starts at the provided fields relative to the order of the query.

@NonNull Query

Creates and returns a new Query that starts at the provided document (inclusive).

@NonNull Query
where(@NonNull Filter filter)

Creates and returns a new Query with the additional filter.

@NonNull Query

Creates and returns a new Query with the additional filter that documents must contain the specified field, the value must be an array, and that the array must contain the provided value.

@NonNull Query

Creates and returns a new Query with the additional filter that documents must contain the specified field, the value must be an array, and that the array must contain the provided value.

@NonNull Query

Creates and returns a new Query with the additional filter that documents must contain the specified field, the value must be an array, and that the array must contain at least one value from the provided list.

@NonNull Query
whereArrayContainsAny(
    @NonNull FieldPath fieldPath,
    @NonNull List<Object> values
)

Creates and returns a new Query with the additional filter that documents must contain the specified field, the value must be an array, and that the array must contain at least one value from the provided list.

@NonNull Query

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.

@NonNull Query

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.

@NonNull Query

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.

@NonNull Query

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.

@NonNull Query

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.

@NonNull Query
whereGreaterThanOrEqualTo(
    @NonNull FieldPath fieldPath,
    @NonNull 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.

@NonNull Query
whereIn(@NonNull String field, @NonNull List<Object> values)

Creates and returns a new Query with the additional filter that documents must contain the specified field and the value must equal one of the values from the provided list.

@NonNull Query
whereIn(@NonNull FieldPath fieldPath, @NonNull List<Object> values)

Creates and returns a new Query with the additional filter that documents must contain the specified field and the value must equal one of the values from the provided list.

@NonNull Query

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.

@NonNull Query

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.

@NonNull Query

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.

@NonNull Query

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.

@NonNull Query

Creates and returns a new Query with the additional filter that documents must contain the specified field and the value does not equal the specified value.

@NonNull Query

Creates and returns a new Query with the additional filter that documents must contain the specified field and the value does not equal the specified value.

@NonNull Query

Creates and returns a new Query with the additional filter that documents must contain the specified field and the value does not equal any of the values from the provided list.

@NonNull Query
whereNotIn(@NonNull FieldPath fieldPath, @NonNull List<Object> values)

Creates and returns a new Query with the additional filter that documents must contain the specified field and the value does not equal any of the values from the provided list.

Extension functions

final @NonNull Flow<@NonNull List<@NonNull T>>
<T extends Object> FirestoreKt.dataObjects(
    @NonNull Query receiver,
    @NonNull MetadataChanges metadataChanges
)

Starts listening to this query with the given options and emits its values converted to a POJO via a Flow.

final @NonNull Flow<@NonNull List<@NonNull T>>
<T extends Object> FirestoreKt.dataObjects(
    @NonNull Query receiver,
    @NonNull MetadataChanges metadataChanges
)

This method is deprecated. Migrate to use the KTX API from the main module: https://firebase.google.com/docs/android/kotlin-migration.

final @NonNull Flow<@NonNull QuerySnapshot>
FirestoreKt.snapshots(
    @NonNull Query receiver,
    @NonNull MetadataChanges metadataChanges
)

Starts listening to this query with the given options and emits its values via a Flow.

final @NonNull Flow<@NonNull QuerySnapshot>
FirestoreKt.snapshots(
    @NonNull Query receiver,
    @NonNull MetadataChanges metadataChanges
)

This method is deprecated. Migrate to use the KTX API from the main module: https://firebase.google.com/docs/android/kotlin-migration.

Public fields

firestore

public final FirebaseFirestore firestore

Public methods

addSnapshotListener

public @NonNull ListenerRegistration addSnapshotListener(@NonNull EventListener<QuerySnapshot> listener)

Starts listening to this query.

Parameters
@NonNull EventListener<QuerySnapshot> listener

The event listener that will be called with the snapshots.

Returns
@NonNull ListenerRegistration

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

addSnapshotListener

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

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

The listener will be automatically removed during onStop.

Parameters
@NonNull Activity activity

The activity to scope the listener to.

@NonNull EventListener<QuerySnapshot> listener

The event listener that will be called with the snapshots.

Returns
@NonNull ListenerRegistration

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

addSnapshotListener

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

Starts listening to this query.

Parameters
@NonNull Executor executor

The executor to use to call the listener.

@NonNull EventListener<QuerySnapshot> listener

The event listener that will be called with the snapshots.

Returns
@NonNull ListenerRegistration

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

addSnapshotListener

public @NonNull ListenerRegistration addSnapshotListener(
    @NonNull MetadataChanges metadataChanges,
    @NonNull EventListener<QuerySnapshot> listener
)

Starts listening to this query with the given options.

Parameters
@NonNull MetadataChanges metadataChanges

Indicates whether metadata-only changes (specifically, only QuerySnapshot.getMetadata() changed) should trigger snapshot events.

@NonNull EventListener<QuerySnapshot> listener

The event listener that will be called with the snapshots.

Returns
@NonNull ListenerRegistration

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

addSnapshotListener

public @NonNull ListenerRegistration addSnapshotListener(
    @NonNull Activity activity,
    @NonNull MetadataChanges metadataChanges,
    @NonNull 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
@NonNull Activity activity

The activity to scope the listener to.

@NonNull MetadataChanges metadataChanges

Indicates whether metadata-only changes (specifically, only QuerySnapshot.getMetadata() changed) should trigger snapshot events.

@NonNull EventListener<QuerySnapshot> listener

The event listener that will be called with the snapshots.

Returns
@NonNull ListenerRegistration

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

addSnapshotListener

public @NonNull ListenerRegistration addSnapshotListener(
    @NonNull Executor executor,
    @NonNull MetadataChanges metadataChanges,
    @NonNull EventListener<QuerySnapshot> listener
)

Starts listening to this query with the given options.

Parameters
@NonNull Executor executor

The executor to use to call the listener.

@NonNull MetadataChanges metadataChanges

Indicates whether metadata-only changes (specifically, only QuerySnapshot.getMetadata() changed) should trigger snapshot events.

@NonNull EventListener<QuerySnapshot> listener

The event listener that will be called with the snapshots.

Returns
@NonNull ListenerRegistration

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

aggregate

public @NonNull AggregateQuery aggregate(
    @NonNull AggregateField aggregateField,
    @NonNull AggregateField[] aggregateFields
)

Calculates the specified aggregations over the documents in the result set of the given query without actually downloading the documents.

Using the returned query to perform aggregations is efficient because only the final aggregation values, not the documents' data, is downloaded. The returned query can perform aggregations of the documents in cases where the result set is prohibitively large to download entirely (thousands of documents).

Returns
@NonNull AggregateQuery

The AggregateQuery that performs aggregations on the documents in the result set of this query.

count

public @NonNull AggregateQuery count()

Returns a query that counts the documents in the result set of this query.

The returned query, when executed, counts the documents in the result set of this query without actually downloading the documents.

Using the returned query to count the documents is efficient because only the final count, not the documents' data, is downloaded. The returned query can count the documents in cases where the result set is prohibitively large to download entirely (thousands of documents).

Returns
@NonNull AggregateQuery

The AggregateQuery that counts the documents in the result set of this query.

endAt

public @NonNull 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
Object[] fieldValues

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

Returns
@NonNull Query

The created Query.

endAt

public @NonNull Query endAt(@NonNull 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
@NonNull DocumentSnapshot snapshot

The snapshot of the document to end at.

Returns
@NonNull Query

The created Query.

endBefore

public @NonNull 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
Object[] fieldValues

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

Returns
@NonNull Query

The created Query.

endBefore

public @NonNull Query endBefore(@NonNull 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
@NonNull DocumentSnapshot snapshot

The snapshot of the document to end before.

Returns
@NonNull Query

The created Query.

equals

public boolean equals(Object o)

get

public @NonNull Task<QuerySnapshotget()

Executes the query and returns the results as a QuerySnapshot.

Returns
@NonNull Task<QuerySnapshot>

A Task that will be resolved with the results of the Query.

get

public @NonNull Task<QuerySnapshotget(@NonNull Source source)

Executes the query and returns the results as a QuerySnapshot.

By default, get() attempts to provide up-to-date data when possible by waiting for data from the server, but it may return cached data or fail if you are offline and the server cannot be reached. This behavior can be altered via the Source parameter.

Parameters
@NonNull Source source

A value to configure the get behavior.

Returns
@NonNull Task<QuerySnapshot>

A Task that will be resolved with the results of the Query.

getFirestore

public @NonNull FirebaseFirestore getFirestore()

Gets the Cloud Firestore instance associated with this query.

hashCode

public int hashCode()

limit

public @NonNull Query limit(long limit)

Creates and returns a new Query that only returns the first matching documents up to the specified number.

Parameters
long limit

The maximum number of items to return.

Returns
@NonNull Query

The created Query.

limitToLast

public @NonNull Query limitToLast(long limit)

Creates and returns a new Query that only returns the last matching documents up to the specified number.

You must specify at least one orderBy clause for limitToLast queries, otherwise an exception will be thrown during execution.

Parameters
long limit

The maximum number of items to return.

Returns
@NonNull Query

The created Query.

orderBy

public @NonNull Query orderBy(@NonNull String field)

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

Parameters
@NonNull String field

The field to sort by.

Returns
@NonNull Query

The created Query.

orderBy

public @NonNull Query orderBy(@NonNull FieldPath fieldPath)

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

Parameters
@NonNull FieldPath fieldPath

The field to sort by.

Returns
@NonNull Query

The created Query.

orderBy

public @NonNull Query orderBy(@NonNull String field, @NonNull 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
@NonNull String field

The field to sort by.

@NonNull Query.Direction direction

The direction to sort.

Returns
@NonNull Query

The created Query.

orderBy

public @NonNull Query orderBy(@NonNull FieldPath fieldPath, @NonNull 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
@NonNull FieldPath fieldPath

The field to sort by.

@NonNull Query.Direction direction

The direction to sort.

Returns
@NonNull Query

The created Query.

startAfter

public @NonNull 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
Object[] fieldValues

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

Returns
@NonNull Query

The created Query.

startAfter

public @NonNull Query startAfter(@NonNull 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
@NonNull DocumentSnapshot snapshot

The snapshot of the document to start after.

Returns
@NonNull Query

The created Query.

startAt

public @NonNull 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
Object[] fieldValues

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

Returns
@NonNull Query

The created Query.

startAt

public @NonNull Query startAt(@NonNull 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
@NonNull DocumentSnapshot snapshot

The snapshot of the document to start at.

Returns
@NonNull Query

The created Query.

where

public @NonNull Query where(@NonNull Filter filter)

Creates and returns a new Query with the additional filter.

Parameters
@NonNull Filter filter

The new filter to apply to the existing query.

Returns
@NonNull Query

The newly created Query.

whereArrayContains

public @NonNull Query whereArrayContains(@NonNull String field, @NonNull Object value)

Creates and returns a new Query with the additional filter that documents must contain the specified field, the value must be an array, and that the array must contain the provided value.

A Query can have only one whereArrayContains() filter and it cannot be combined with whereArrayContainsAny().

Parameters
@NonNull String field

The name of the field containing an array to search.

@NonNull Object value

The value that must be contained in the array

Returns
@NonNull Query

The created Query.

whereArrayContains

public @NonNull Query whereArrayContains(@NonNull FieldPath fieldPath, @NonNull Object value)

Creates and returns a new Query with the additional filter that documents must contain the specified field, the value must be an array, and that the array must contain the provided value.

A Query can have only one whereArrayContains() filter and it cannot be combined with whereArrayContainsAny().

Parameters
@NonNull FieldPath fieldPath

The path of the field containing an array to search.

@NonNull Object value

The value that must be contained in the array

Returns
@NonNull Query

The created Query.

whereArrayContainsAny

public @NonNull Query whereArrayContainsAny(@NonNull String field, @NonNull List<Object> values)

Creates and returns a new Query with the additional filter that documents must contain the specified field, the value must be an array, and that the array must contain at least one value from the provided list.

A Query can have only one whereArrayContainsAny() filter and it cannot be combined with whereArrayContains() or whereIn().

Parameters
@NonNull String field

The name of the field containing an array to search.

@NonNull List<Object> values

The list that contains the values to match.

Returns
@NonNull Query

The created Query.

whereArrayContainsAny

public @NonNull Query whereArrayContainsAny(
    @NonNull FieldPath fieldPath,
    @NonNull List<Object> values
)

Creates and returns a new Query with the additional filter that documents must contain the specified field, the value must be an array, and that the array must contain at least one value from the provided list.

A Query can have only one whereArrayContainsAny() filter and it cannot be combined with whereArrayContains() or whereIn().

Parameters
@NonNull FieldPath fieldPath

The path of the field containing an array to search.

@NonNull List<Object> values

The list that contains the values to match.

Returns
@NonNull Query

The created Query.

whereEqualTo

public @NonNull Query whereEqualTo(@NonNull String field, @Nullable 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
@NonNull String field

The name of the field to compare

@Nullable Object value

The value for comparison

Returns
@NonNull Query

The created Query.

whereEqualTo

public @NonNull Query whereEqualTo(@NonNull FieldPath fieldPath, @Nullable 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
@NonNull FieldPath fieldPath

The path of the field to compare

@Nullable Object value

The value for comparison

Returns
@NonNull Query

The created Query.

whereGreaterThan

public @NonNull Query whereGreaterThan(@NonNull String field, @NonNull 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
@NonNull String field

The name of the field to compare

@NonNull Object value

The value for comparison

Returns
@NonNull Query

The created Query.

whereGreaterThan

public @NonNull Query whereGreaterThan(@NonNull FieldPath fieldPath, @NonNull 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
@NonNull FieldPath fieldPath

The path of the field to compare

@NonNull Object value

The value for comparison

Returns
@NonNull Query

The created Query.

whereGreaterThanOrEqualTo

public @NonNull Query whereGreaterThanOrEqualTo(@NonNull String field, @NonNull 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
@NonNull String field

The name of the field to compare

@NonNull Object value

The value for comparison

Returns
@NonNull Query

The created Query.

whereGreaterThanOrEqualTo

public @NonNull Query whereGreaterThanOrEqualTo(
    @NonNull FieldPath fieldPath,
    @NonNull 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
@NonNull FieldPath fieldPath

The path of the field to compare

@NonNull Object value

The value for comparison

Returns
@NonNull Query

The created Query.

whereIn

public @NonNull Query whereIn(@NonNull String field, @NonNull List<Object> values)

Creates and returns a new Query with the additional filter that documents must contain the specified field and the value must equal one of the values from the provided list.

A Query can have only one whereIn() filter, and it cannot be combined with whereArrayContainsAny().

Parameters
@NonNull String field

The name of the field to search.

@NonNull List<Object> values

The list that contains the values to match.

Returns
@NonNull Query

The created Query.

whereIn

public @NonNull Query whereIn(@NonNull FieldPath fieldPath, @NonNull List<Object> values)

Creates and returns a new Query with the additional filter that documents must contain the specified field and the value must equal one of the values from the provided list.

A Query can have only one whereIn() filter, and it cannot be combined with whereArrayContainsAny().

Parameters
@NonNull FieldPath fieldPath

The path of the field to search.

@NonNull List<Object> values

The list that contains the values to match.

Returns
@NonNull Query

The created Query.

whereLessThan

public @NonNull Query whereLessThan(@NonNull String field, @NonNull 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
@NonNull String field

The name of the field to compare

@NonNull Object value

The value for comparison

Returns
@NonNull Query

The created Query.

whereLessThan

public @NonNull Query whereLessThan(@NonNull FieldPath fieldPath, @NonNull 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
@NonNull FieldPath fieldPath

The path of the field to compare

@NonNull Object value

The value for comparison

Returns
@NonNull Query

The created Query.

whereLessThanOrEqualTo

public @NonNull Query whereLessThanOrEqualTo(@NonNull String field, @NonNull 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
@NonNull String field

The name of the field to compare

@NonNull Object value

The value for comparison

Returns
@NonNull Query

The created Query.

whereLessThanOrEqualTo

public @NonNull Query whereLessThanOrEqualTo(@NonNull FieldPath fieldPath, @NonNull 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
@NonNull FieldPath fieldPath

The path of the field to compare

@NonNull Object value

The value for comparison

Returns
@NonNull Query

The created Query.

whereNotEqualTo

public @NonNull Query whereNotEqualTo(@NonNull String field, @Nullable Object value)

Creates and returns a new Query with the additional filter that documents must contain the specified field and the value does not equal the specified value.

A Query can have only one whereNotEqualTo() filter, and it cannot be combined with whereNotIn().

Parameters
@NonNull String field

The name of the field to compare

@Nullable Object value

The value for comparison

Returns
@NonNull Query

The created Query.

whereNotEqualTo

public @NonNull Query whereNotEqualTo(@NonNull FieldPath fieldPath, @Nullable Object value)

Creates and returns a new Query with the additional filter that documents must contain the specified field and the value does not equal the specified value.

A Query can have only one whereNotEqualTo() filter, and it cannot be combined with whereNotIn().

Parameters
@NonNull FieldPath fieldPath

The path of the field to compare

@Nullable Object value

The value for comparison

Returns
@NonNull Query

The created Query.

whereNotIn

public @NonNull Query whereNotIn(@NonNull String field, @NonNull List<Object> values)

Creates and returns a new Query with the additional filter that documents must contain the specified field and the value does not equal any of the values from the provided list.

One special case is that whereNotIn cannot match null values. To query for documents where a field exists and is null, use whereNotEqualTo, which can handle this special case.

A Query can have only one whereNotIn() filter, and it cannot be combined with whereArrayContains(), whereArrayContainsAny(), whereIn(), or whereNotEqualTo().

Parameters
@NonNull String field

The name of the field to search.

@NonNull List<Object> values

The list that contains the values to match.

Returns
@NonNull Query

The created Query.

whereNotIn

public @NonNull Query whereNotIn(@NonNull FieldPath fieldPath, @NonNull List<Object> values)

Creates and returns a new Query with the additional filter that documents must contain the specified field and the value does not equal any of the values from the provided list.

One special case is that whereNotIn cannot match null values. To query for documents where a field exists and is null, use whereNotEqualTo, which can handle this special case.

A Query can have only one whereNotIn() filter, and it cannot be combined with whereArrayContains(), whereArrayContainsAny(), whereIn(), or whereNotEqualTo().

Parameters
@NonNull FieldPath fieldPath

The path of the field to search.

@NonNull List<Object> values

The list that contains the values to match.

Returns
@NonNull Query

The created Query.

Extension functions

FirestoreKt.dataObjects

public final @NonNull Flow<@NonNull List<@NonNull T>> <T extends Object> FirestoreKt.dataObjects(
    @NonNull Query receiver,
    @NonNull MetadataChanges metadataChanges
)

Starts listening to this query with the given options and emits its values converted to a POJO via a Flow.

  • When the returned flow starts being collected, an EventListener will be attached.

  • When the flow completes, the listener will be removed.

Parameters
<T extends Object>

The type of the object to convert to.

@NonNull MetadataChanges metadataChanges

controls metadata-only changes. Default: MetadataChanges.EXCLUDE

FirestoreKt.dataObjects

public final @NonNull Flow<@NonNull List<@NonNull T>> <T extends Object> FirestoreKt.dataObjects(
    @NonNull Query receiver,
    @NonNull MetadataChanges metadataChanges
)

Starts listening to this query with the given options and emits its values converted to a POJO via a Flow.

  • When the returned flow starts being collected, an EventListener will be attached.

  • When the flow completes, the listener will be removed.

Deprecation Notice: The Kotlin extensions (KTX) APIs have been added to their respective main modules, and the Kotlin extension (KTX) APIs in com.google.firebase.firebase-database-ktx are now deprecated. As early as April 2024, we'll no longer release KTX modules. For details, see the FAQ about this initiative.

Parameters
<T extends Object>

The type of the object to convert to.

@NonNull MetadataChanges metadataChanges

controls metadata-only changes. Default: MetadataChanges.EXCLUDE

FirestoreKt.snapshots

public final @NonNull Flow<@NonNull QuerySnapshotFirestoreKt.snapshots(
    @NonNull Query receiver,
    @NonNull MetadataChanges metadataChanges
)

Starts listening to this query with the given options and emits its values via a Flow.

  • When the returned flow starts being collected, an EventListener will be attached.

  • When the flow completes, the listener will be removed.

Parameters
@NonNull MetadataChanges metadataChanges

controls metadata-only changes. Default: MetadataChanges.EXCLUDE

FirestoreKt.snapshots

public final @NonNull Flow<@NonNull QuerySnapshotFirestoreKt.snapshots(
    @NonNull Query receiver,
    @NonNull MetadataChanges metadataChanges
)

Starts listening to this query with the given options and emits its values via a Flow.

  • When the returned flow starts being collected, an EventListener will be attached.

  • When the flow completes, the listener will be removed.

Deprecation Notice: The Kotlin extensions (KTX) APIs have been added to their respective main modules, and the Kotlin extension (KTX) APIs in com.google.firebase.firebase-database-ktx are now deprecated. As early as April 2024, we'll no longer release KTX modules. For details, see the FAQ about this initiative.

Parameters
@NonNull MetadataChanges metadataChanges

controls metadata-only changes. Default: MetadataChanges.EXCLUDE