QuerySnapshot

public class QuerySnapshot implements Iterable


A QuerySnapshot contains the results of a query. It can contain zero or more DocumentSnapshot objects.

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

Public fields

final SnapshotMetadata

Public methods

boolean
@NonNullList<DocumentChange>

Returns the list of documents that changed since the last snapshot.

@NonNullList<DocumentChange>

Returns the list of documents that changed since the last snapshot.

@NonNullList<DocumentSnapshot>

Returns the documents in this QuerySnapshot as a List in order of the query.

@NonNullSnapshotMetadata
@NonNullQuery
int
boolean

Returns true if there are no documents in the QuerySnapshot.

@NonNullIterator<QueryDocumentSnapshot>
int

Returns the number of documents in the QuerySnapshot.

@NonNullList<T>
<T> toObjects(@NonNullClass<T> clazz)

Returns the contents of the documents in the QuerySnapshot, converted to the provided class, as a list.

@NonNullList<T>
<T> toObjects(
    @NonNullClass<T> clazz,
    @NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the contents of the documents in the QuerySnapshot, converted to the provided class, as a list.

Extension functions

final @NonNullList<@NonNull T>

Returns the contents of the documents in the QuerySnapshot, converted to the provided class, as a list.

final @NonNullList<@NonNull T>
<T extends Object> FirestoreKt.toObjects(
    @NonNullQuerySnapshot receiver,
    @NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the contents of the documents in the QuerySnapshot, converted to the provided class, as a list.

final @NonNullList<@NonNull T>

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

final @NonNullList<@NonNull T>
<T extends Object> FirestoreKt.toObjects(
    @NonNullQuerySnapshot receiver,
    @NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

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

Inherited methods

From java.lang.Iterable

Public fields

metadata

public final SnapshotMetadata metadata

Public methods

equals

public boolean equals(@NullableObject obj)

getDocumentChanges

public @NonNullList<DocumentChangegetDocumentChanges()

Returns the list of documents that changed since the last snapshot. If it's the first snapshot all documents will be in the list as added changes.

Documents with changes only to their metadata will not be included.

Returns
@NonNullList<DocumentChange>

The list of document changes since the last snapshot.

getDocumentChanges

public @NonNullList<DocumentChangegetDocumentChanges(@NonNullMetadataChanges metadataChanges)

Returns the list of documents that changed since the last snapshot. If it's the first snapshot all documents will be in the list as added changes.

Parameters
@NonNullMetadataChanges metadataChanges

Indicates whether metadata-only changes (specifically, only DocumentSnapshot.getMetadata() changed) should be included.

Returns
@NonNullList<DocumentChange>

The list of document changes since the last snapshot.

getDocuments

public @NonNullList<DocumentSnapshotgetDocuments()

Returns the documents in this QuerySnapshot as a List in order of the query.

Returns
@NonNullList<DocumentSnapshot>

The list of documents.

getMetadata

public @NonNullSnapshotMetadata getMetadata()
Returns
@NonNullSnapshotMetadata

The metadata for this query snapshot.

getQuery

public @NonNullQuery getQuery()

hashCode

public int hashCode()

isEmpty

public boolean isEmpty()

Returns true if there are no documents in the QuerySnapshot.

size

public int size()

Returns the number of documents in the QuerySnapshot.

toObjects

public @NonNullList<T> <T> toObjects(@NonNullClass<T> clazz)

Returns the contents of the documents in the QuerySnapshot, converted to the provided class, as a list.

Parameters
@NonNullClass<T> clazz

The POJO type used to convert the documents in the list.

toObjects

public @NonNullList<T> <T> toObjects(
    @NonNullClass<T> clazz,
    @NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the contents of the documents in the QuerySnapshot, converted to the provided class, as a list.

Parameters
@NonNullClass<T> clazz

The POJO type used to convert the documents in the list.

@NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior

Configures the behavior for server timestamps that have not yet been set to their final value.

Extension functions

FirestoreKt.toObjects

public final @NonNullList<@NonNull T> <T extends Object> FirestoreKt.toObjects(@NonNullQuerySnapshot receiver)

Returns the contents of the documents in the QuerySnapshot, converted to the provided class, as a list.

Parameters
<T extends Object>

The POJO type used to convert the documents in the list.

FirestoreKt.toObjects

public final @NonNullList<@NonNull T> <T extends Object> FirestoreKt.toObjects(
    @NonNullQuerySnapshot receiver,
    @NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the contents of the documents in the QuerySnapshot, converted to the provided class, as a list.

Parameters
<T extends Object>

The POJO type used to convert the documents in the list.

@NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior

Configures the behavior for server timestamps that have not yet

 been set to their final value.

FirestoreKt.toObjects

public final @NonNullList<@NonNull T> <T extends Object> FirestoreKt.toObjects(@NonNullQuerySnapshot receiver)

Returns the contents of the documents in the QuerySnapshot, converted to the provided class, as a list.

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 POJO type used to convert the documents in the list.

FirestoreKt.toObjects

public final @NonNullList<@NonNull T> <T extends Object> FirestoreKt.toObjects(
    @NonNullQuerySnapshot receiver,
    @NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the contents of the documents in the QuerySnapshot, converted to the provided class, as a list.

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 POJO type used to convert the documents in the list.

@NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior

Configures the behavior for server timestamps that have not yet

 been set to their final value.