Query

public classQuery

Known direct subclasses
CollectionReference

ACollectionReference can be used for adding documents, getting document references, and querying for documents (using the methods inherited fromQuery).


AQuery which you can read or listen to. You can also construct refinedQuery 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 enumQuery.Direction

An enum for the direction of a sort.

Public fields

finalFirebaseFirestore

Public methods

@NonNullListenerRegistration

Starts listening to this query.

@NonNullListenerRegistration

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

@NonNullListenerRegistration

Starts listening to this query.

@NonNullListenerRegistration
addSnapshotListener(
    @NonNullMetadataChanges metadataChanges,
    @NonNullEventListener<QuerySnapshot> listener
)

Starts listening to this query with the given options.

@NonNullListenerRegistration

Starts listening to this query with the given options.

@NonNullListenerRegistration
addSnapshotListener(
    @NonNullActivity activity,
    @NonNullMetadataChanges metadataChanges,
    @NonNullEventListener<QuerySnapshot> listener
)

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

@NonNullListenerRegistration
addSnapshotListener(
    @NonNullExecutor executor,
    @NonNullMetadataChanges metadataChanges,
    @NonNullEventListener<QuerySnapshot> listener
)

Starts listening to this query with the given options.

@NonNullAggregateQuery
aggregate(
    @NonNullAggregateField aggregateField,
    @NonNull AggregateField[] aggregateFields
)

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

@NonNullAggregateQuery

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

@NonNullQuery
endAt(Object[] fieldValues)

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

@NonNullQuery

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

@NonNullQuery
endBefore(Object[] fieldValues)

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

@NonNullQuery

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

boolean
@NonNullTask<QuerySnapshot>
get()

Executes the query and returns the results as aQuerySnapshot.

@NonNullTask<QuerySnapshot>
get(@NonNullSource source)

Executes the query and returns the results as aQuerySnapshot.

@NonNullFirebaseFirestore

Gets the Cloud Firestore instance associated with this query.

int
@NonNullQuery
limit(long limit)

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

@NonNullQuery
limitToLast(long limit)

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

@NonNullQuery

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

@NonNullQuery

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

@NonNullQuery

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

@NonNullQuery

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

@NonNullQuery
startAfter(Object[] fieldValues)

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

@NonNullQuery

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

@NonNullQuery
startAt(Object[] fieldValues)

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

@NonNullQuery

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

@NonNullQuery

Creates and returns a newQuery with the additional filter.

@NonNullQuery

Creates and returns a newQuery 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.

@NonNullQuery

Creates and returns a newQuery 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.

@NonNullQuery

Creates and returns a newQuery 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.

@NonNullQuery
whereArrayContainsAny(
    @NonNullFieldPath fieldPath,
    @NonNullList<Object> values
)

Creates and returns a newQuery 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.

@NonNullQuery

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

@NonNullQuery

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

@NonNullQuery

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

@NonNullQuery

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

@NonNullQuery

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

@NonNullQuery
whereGreaterThanOrEqualTo(
    @NonNullFieldPath fieldPath,
    @NonNullObject value
)

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

@NonNullQuery

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

@NonNullQuery
whereIn(@NonNullFieldPath fieldPath, @NonNullList<Object> values)

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

@NonNullQuery

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

@NonNullQuery

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

@NonNullQuery

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

@NonNullQuery

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

@NonNullQuery

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

@NonNullQuery

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

@NonNullQuery

Creates and returns a newQuery 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.

@NonNullQuery

Creates and returns a newQuery 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 @NonNullFlow<@NonNullList<@NonNull T>>
<T extends Object>FirestoreKt.dataObjects(
    @NonNullQuery receiver,
    @NonNullMetadataChanges metadataChanges
)

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

final @NonNullFlow<@NonNullQuerySnapshot>
FirestoreKt.snapshots(
    @NonNullQuery receiver,
    @NonNullMetadataChanges metadataChanges
)

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

Public fields

firestore

public final FirebaseFirestore firestore

Public methods

addSnapshotListener

public @NonNullListenerRegistration addSnapshotListener(@NonNullEventListener<QuerySnapshot> listener)

Starts listening to this query.

Parameters
@NonNullEventListener<QuerySnapshot> listener

The event listener that will be called with the snapshots.

Returns
@NonNullListenerRegistration

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

addSnapshotListener

public @NonNullListenerRegistration addSnapshotListener(
    @NonNullActivity activity,
    @NonNullEventListener<QuerySnapshot> listener
)

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

The listener will be automatically removed duringonStop.

Parameters
@NonNullActivity activity

The activity to scope the listener to.

@NonNullEventListener<QuerySnapshot> listener

The event listener that will be called with the snapshots.

Returns
@NonNullListenerRegistration

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

addSnapshotListener

public @NonNullListenerRegistration addSnapshotListener(
    @NonNullExecutor executor,
    @NonNullEventListener<QuerySnapshot> listener
)

Starts listening to this query.

Parameters
@NonNullExecutor executor

The executor to use to call the listener.

@NonNullEventListener<QuerySnapshot> listener

The event listener that will be called with the snapshots.

Returns
@NonNullListenerRegistration

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

addSnapshotListener

public @NonNullListenerRegistration addSnapshotListener(
    @NonNullMetadataChanges metadataChanges,
    @NonNullEventListener<QuerySnapshot> listener
)

Starts listening to this query with the given options.

Parameters
@NonNullMetadataChanges metadataChanges

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

@NonNullEventListener<QuerySnapshot> listener

The event listener that will be called with the snapshots.

Returns
@NonNullListenerRegistration

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

addSnapshotListener

public @NonNullListenerRegistration addSnapshotListener(
    @NonNullSnapshotListenOptions options,
    @NonNullEventListener<QuerySnapshot> listener
)

Starts listening to this query with the given options.

Parameters
@NonNullSnapshotListenOptions options

Sets snapshot listener options, including whether metadata-only changes should trigger snapshot events, the source to listen to, the executor to use to call the listener, or the activity to scope the listener to.

@NonNullEventListener<QuerySnapshot> listener

The event listener that will be called with the snapshots.

Returns
@NonNullListenerRegistration

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

addSnapshotListener

public @NonNullListenerRegistration addSnapshotListener(
    @NonNullActivity activity,
    @NonNullMetadataChanges metadataChanges,
    @NonNullEventListener<QuerySnapshot> listener
)

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

The listener will be automatically removed duringonStop.

Parameters
@NonNullActivity activity

The activity to scope the listener to.

@NonNullMetadataChanges metadataChanges

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

@NonNullEventListener<QuerySnapshot> listener

The event listener that will be called with the snapshots.

Returns
@NonNullListenerRegistration

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

addSnapshotListener

public @NonNullListenerRegistration addSnapshotListener(
    @NonNullExecutor executor,
    @NonNullMetadataChanges metadataChanges,
    @NonNullEventListener<QuerySnapshot> listener
)

Starts listening to this query with the given options.

Parameters
@NonNullExecutor executor

The executor to use to call the listener.

@NonNullMetadataChanges metadataChanges

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

@NonNullEventListener<QuerySnapshot> listener

The event listener that will be called with the snapshots.

Returns
@NonNullListenerRegistration

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

aggregate

public @NonNullAggregateQuery aggregate(
    @NonNullAggregateField 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
@NonNullAggregateQuery

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

count

public @NonNullAggregateQuery 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 querywithout 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
@NonNullAggregateQuery

TheAggregateQuery that counts the documents in the result set of this query.

endAt

public @NonNullQuery endAt(Object[] fieldValues)

Creates and returns a newQuery 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
@NonNullQuery

The createdQuery.

endAt

public @NonNullQuery endAt(@NonNullDocumentSnapshot snapshot)

Creates and returns a newQuery 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
@NonNullDocumentSnapshot snapshot

The snapshot of the document to end at.

Returns
@NonNullQuery

The createdQuery.

endBefore

public @NonNullQuery endBefore(Object[] fieldValues)

Creates and returns a newQuery 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
@NonNullQuery

The createdQuery.

endBefore

public @NonNullQuery endBefore(@NonNullDocumentSnapshot snapshot)

Creates and returns a newQuery 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
@NonNullDocumentSnapshot snapshot

The snapshot of the document to end before.

Returns
@NonNullQuery

The createdQuery.

equals

public boolean equals(Object o)

get

public @NonNullTask<QuerySnapshotget()

Executes the query and returns the results as aQuerySnapshot.

Returns
@NonNullTask<QuerySnapshot>

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

get

public @NonNullTask<QuerySnapshotget(@NonNullSource source)

Executes the query and returns the results as aQuerySnapshot.

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 theSource parameter.

Parameters
@NonNullSource source

A value to configure the get behavior.

Returns
@NonNullTask<QuerySnapshot>

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

getFirestore

public @NonNullFirebaseFirestore getFirestore()

Gets the Cloud Firestore instance associated with this query.

hashCode

public int hashCode()

limit

public @NonNullQuery limit(long limit)

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

Parameters
long limit

The maximum number of items to return.

Returns
@NonNullQuery

The createdQuery.

limitToLast

public @NonNullQuery limitToLast(long limit)

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

You must specify at least oneorderBy clause forlimitToLast queries, otherwise an exception will be thrown during execution.

Parameters
long limit

The maximum number of items to return.

Returns
@NonNullQuery

The createdQuery.

orderBy

public @NonNullQuery orderBy(@NonNullString field)

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

Parameters
@NonNullString field

The field to sort by.

Returns
@NonNullQuery

The createdQuery.

orderBy

public @NonNullQuery orderBy(@NonNullFieldPath fieldPath)

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

Parameters
@NonNullFieldPath fieldPath

The field to sort by.

Returns
@NonNullQuery

The createdQuery.

orderBy

public @NonNullQuery orderBy(@NonNullString field, @NonNullQuery.Direction direction)

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

Parameters
@NonNullString field

The field to sort by.

@NonNullQuery.Direction direction

The direction to sort.

Returns
@NonNullQuery

The createdQuery.

orderBy

public @NonNullQuery orderBy(@NonNullFieldPath fieldPath, @NonNullQuery.Direction direction)

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

Parameters
@NonNullFieldPath fieldPath

The field to sort by.

@NonNullQuery.Direction direction

The direction to sort.

Returns
@NonNullQuery

The createdQuery.

startAfter

public @NonNullQuery startAfter(Object[] fieldValues)

Creates and returns a newQuery 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
@NonNullQuery

The createdQuery.

startAfter

public @NonNullQuery startAfter(@NonNullDocumentSnapshot snapshot)

Creates and returns a newQuery 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
@NonNullDocumentSnapshot snapshot

The snapshot of the document to start after.

Returns
@NonNullQuery

The createdQuery.

startAt

public @NonNullQuery startAt(Object[] fieldValues)

Creates and returns a newQuery 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
@NonNullQuery

The createdQuery.

startAt

public @NonNullQuery startAt(@NonNullDocumentSnapshot snapshot)

Creates and returns a newQuery 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
@NonNullDocumentSnapshot snapshot

The snapshot of the document to start at.

Returns
@NonNullQuery

The createdQuery.

where

public @NonNullQuery where(@NonNullFilter filter)

Creates and returns a newQuery with the additional filter.

Parameters
@NonNullFilter filter

The new filter to apply to the existing query.

Returns
@NonNullQuery

The newly createdQuery.

whereArrayContains

public @NonNullQuery whereArrayContains(@NonNullString field, @NonNullObject value)

Creates and returns a newQuery 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.

AQuery can have only onewhereArrayContains() filter and it cannot be combined withwhereArrayContainsAny().

Parameters
@NonNullString field

The name of the field containing an array to search.

@NonNullObject value

The value that must be contained in the array

Returns
@NonNullQuery

The createdQuery.

whereArrayContains

public @NonNullQuery whereArrayContains(@NonNullFieldPath fieldPath, @NonNullObject value)

Creates and returns a newQuery 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.

AQuery can have only onewhereArrayContains() filter and it cannot be combined withwhereArrayContainsAny().

Parameters
@NonNullFieldPath fieldPath

The path of the field containing an array to search.

@NonNullObject value

The value that must be contained in the array

Returns
@NonNullQuery

The createdQuery.

whereArrayContainsAny

public @NonNullQuery whereArrayContainsAny(@NonNullString field, @NonNullList<Object> values)

Creates and returns a newQuery 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.

AQuery can have only onewhereArrayContainsAny() filter and it cannot be combined withwhereArrayContains() orwhereIn().

Parameters
@NonNullString field

The name of the field containing an array to search.

@NonNullList<Object> values

The list that contains the values to match.

Returns
@NonNullQuery

The createdQuery.

whereArrayContainsAny

public @NonNullQuery whereArrayContainsAny(
    @NonNullFieldPath fieldPath,
    @NonNullList<Object> values
)

Creates and returns a newQuery 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.

AQuery can have only onewhereArrayContainsAny() filter and it cannot be combined withwhereArrayContains() orwhereIn().

Parameters
@NonNullFieldPath fieldPath

The path of the field containing an array to search.

@NonNullList<Object> values

The list that contains the values to match.

Returns
@NonNullQuery

The createdQuery.

whereEqualTo

public @NonNullQuery whereEqualTo(@NonNullString field, @NullableObject value)

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

Parameters
@NonNullString field

The name of the field to compare

@NullableObject value

The value for comparison

Returns
@NonNullQuery

The createdQuery.

whereEqualTo

public @NonNullQuery whereEqualTo(@NonNullFieldPath fieldPath, @NullableObject value)

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

Parameters
@NonNullFieldPath fieldPath

The path of the field to compare

@NullableObject value

The value for comparison

Returns
@NonNullQuery

The createdQuery.

whereGreaterThan

public @NonNullQuery whereGreaterThan(@NonNullString field, @NonNullObject value)

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

Parameters
@NonNullString field

The name of the field to compare

@NonNullObject value

The value for comparison

Returns
@NonNullQuery

The createdQuery.

whereGreaterThan

public @NonNullQuery whereGreaterThan(@NonNullFieldPath fieldPath, @NonNullObject value)

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

Parameters
@NonNullFieldPath fieldPath

The path of the field to compare

@NonNullObject value

The value for comparison

Returns
@NonNullQuery

The createdQuery.

whereGreaterThanOrEqualTo

public @NonNullQuery whereGreaterThanOrEqualTo(@NonNullString field, @NonNullObject value)

Creates and returns a newQuery 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
@NonNullString field

The name of the field to compare

@NonNullObject value

The value for comparison

Returns
@NonNullQuery

The createdQuery.

whereGreaterThanOrEqualTo

public @NonNullQuery whereGreaterThanOrEqualTo(
    @NonNullFieldPath fieldPath,
    @NonNullObject value
)

Creates and returns a newQuery 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
@NonNullFieldPath fieldPath

The path of the field to compare

@NonNullObject value

The value for comparison

Returns
@NonNullQuery

The createdQuery.

whereIn

public @NonNullQuery whereIn(@NonNullString field, @NonNullList<Object> values)

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

AQuery can have only onewhereIn() filter, and it cannot be combined withwhereArrayContainsAny().

Parameters
@NonNullString field

The name of the field to search.

@NonNullList<Object> values

The list that contains the values to match.

Returns
@NonNullQuery

The createdQuery.

whereIn

public @NonNullQuery whereIn(@NonNullFieldPath fieldPath, @NonNullList<Object> values)

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

AQuery can have only onewhereIn() filter, and it cannot be combined withwhereArrayContainsAny().

Parameters
@NonNullFieldPath fieldPath

The path of the field to search.

@NonNullList<Object> values

The list that contains the values to match.

Returns
@NonNullQuery

The createdQuery.

whereLessThan

public @NonNullQuery whereLessThan(@NonNullString field, @NonNullObject value)

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

Parameters
@NonNullString field

The name of the field to compare

@NonNullObject value

The value for comparison

Returns
@NonNullQuery

The createdQuery.

whereLessThan

public @NonNullQuery whereLessThan(@NonNullFieldPath fieldPath, @NonNullObject value)

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

Parameters
@NonNullFieldPath fieldPath

The path of the field to compare

@NonNullObject value

The value for comparison

Returns
@NonNullQuery

The createdQuery.

whereLessThanOrEqualTo

public @NonNullQuery whereLessThanOrEqualTo(@NonNullString field, @NonNullObject value)

Creates and returns a newQuery 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
@NonNullString field

The name of the field to compare

@NonNullObject value

The value for comparison

Returns
@NonNullQuery

The createdQuery.

whereLessThanOrEqualTo

public @NonNullQuery whereLessThanOrEqualTo(@NonNullFieldPath fieldPath, @NonNullObject value)

Creates and returns a newQuery 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
@NonNullFieldPath fieldPath

The path of the field to compare

@NonNullObject value

The value for comparison

Returns
@NonNullQuery

The createdQuery.

whereNotEqualTo

public @NonNullQuery whereNotEqualTo(@NonNullString field, @NullableObject value)

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

AQuery can have only onewhereNotEqualTo() filter, and it cannot be combined withwhereNotIn().

Parameters
@NonNullString field

The name of the field to compare

@NullableObject value

The value for comparison

Returns
@NonNullQuery

The createdQuery.

whereNotEqualTo

public @NonNullQuery whereNotEqualTo(@NonNullFieldPath fieldPath, @NullableObject value)

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

AQuery can have only onewhereNotEqualTo() filter, and it cannot be combined withwhereNotIn().

Parameters
@NonNullFieldPath fieldPath

The path of the field to compare

@NullableObject value

The value for comparison

Returns
@NonNullQuery

The createdQuery.

whereNotIn

public @NonNullQuery whereNotIn(@NonNullString field, @NonNullList<Object> values)

Creates and returns a newQuery 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 thatwhereNotIn cannot matchnull values. To query for documents where a field exists and isnull, usewhereNotEqualTo, which can handle this special case.

AQuery can have only onewhereNotIn() filter, and it cannot be combined withwhereArrayContains(),whereArrayContainsAny(),whereIn(), orwhereNotEqualTo().

Parameters
@NonNullString field

The name of the field to search.

@NonNullList<Object> values

The list that contains the values to match.

Returns
@NonNullQuery

The createdQuery.

whereNotIn

public @NonNullQuery whereNotIn(@NonNullFieldPath fieldPath, @NonNullList<Object> values)

Creates and returns a newQuery 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 thatwhereNotIn cannot matchnull values. To query for documents where a field exists and isnull, usewhereNotEqualTo, which can handle this special case.

AQuery can have only onewhereNotIn() filter, and it cannot be combined withwhereArrayContains(),whereArrayContainsAny(),whereIn(), orwhereNotEqualTo().

Parameters
@NonNullFieldPath fieldPath

The path of the field to search.

@NonNullList<Object> values

The list that contains the values to match.

Returns
@NonNullQuery

The createdQuery.

Extension functions

FirestoreKt.dataObjects

public final @NonNullFlow<@NonNullList<@NonNull T>> <T extends Object>FirestoreKt.dataObjects(
    @NonNullQuery receiver,
    @NonNullMetadataChanges metadataChanges
)

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

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

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

Parameters
<T extends Object>

The type of the object to convert to.

@NonNullMetadataChanges metadataChanges

controls metadata-only changes. Default:MetadataChanges.EXCLUDE

FirestoreKt.snapshots

public final @NonNullFlow<@NonNullQuerySnapshotFirestoreKt.snapshots(
    @NonNullQuery receiver,
    @NonNullMetadataChanges metadataChanges
)

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

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

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

Parameters
@NonNullMetadataChanges metadataChanges

controls metadata-only changes. Default:MetadataChanges.EXCLUDE

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-07-21 UTC.