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
@NonNull List<DocumentChange>

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

@NonNull List<DocumentChange>

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

@NonNull List<DocumentSnapshot>

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

@NonNull SnapshotMetadata
@NonNull Query
int
boolean

Returns true if there are no documents in the QuerySnapshot.

@NonNull Iterator<QueryDocumentSnapshot>
int

Returns the number of documents in the QuerySnapshot.

@NonNull List<T>
<T> toObjects(@NonNull Class<T> clazz)

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

@NonNull List<T>
<T> toObjects(
    @NonNull Class<T> clazz,
    @NonNull DocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

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

Extension functions

final @NonNull List<@NonNull T>

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

final @NonNull List<@NonNull T>
<T extends Object> FirestoreKt.toObjects(
    @NonNull QuerySnapshot receiver,
    @NonNull DocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

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

final @NonNull List<@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 @NonNull List<@NonNull T>
<T extends Object> FirestoreKt.toObjects(
    @NonNull QuerySnapshot receiver,
    @NonNull DocumentSnapshot.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(@Nullable Object obj)

getDocumentChanges

public @NonNull List<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
@NonNull List<DocumentChange>

The list of document changes since the last snapshot.

getDocumentChanges

public @NonNull List<DocumentChangegetDocumentChanges(@NonNull MetadataChanges 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
@NonNull MetadataChanges metadataChanges

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

Returns
@NonNull List<DocumentChange>

The list of document changes since the last snapshot.

getDocuments

public @NonNull List<DocumentSnapshotgetDocuments()

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

Returns
@NonNull List<DocumentSnapshot>

The list of documents.

getMetadata

public @NonNull SnapshotMetadata getMetadata()
Returns
@NonNull SnapshotMetadata

The metadata for this query snapshot.

getQuery

public @NonNull Query 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 @NonNull List<T> <T> toObjects(@NonNull Class<T> clazz)

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

Parameters
@NonNull Class<T> clazz

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

toObjects

public @NonNull List<T> <T> toObjects(
    @NonNull Class<T> clazz,
    @NonNull DocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

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

Parameters
@NonNull Class<T> clazz

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

@NonNull DocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior

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

Extension functions

FirestoreKt.toObjects

public final @NonNull List<@NonNull T> <T extends Object> FirestoreKt.toObjects(@NonNull QuerySnapshot 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 @NonNull List<@NonNull T> <T extends Object> FirestoreKt.toObjects(
    @NonNull QuerySnapshot receiver,
    @NonNull DocumentSnapshot.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.

@NonNull DocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior

Configures the behavior for server timestamps that have not yet

    been set to their final value.

FirestoreKt.toObjects

public final @NonNull List<@NonNull T> <T extends Object> FirestoreKt.toObjects(@NonNull QuerySnapshot 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 @NonNull List<@NonNull T> <T extends Object> FirestoreKt.toObjects(
    @NonNull QuerySnapshot receiver,
    @NonNull DocumentSnapshot.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.

@NonNull DocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior

Configures the behavior for server timestamps that have not yet

    been set to their final value.