QueryDocumentSnapshot

public class QueryDocumentSnapshot extends DocumentSnapshot


A QueryDocumentSnapshot contains data read from a document in your Cloud Firestore database as part of a query. The document is guaranteed to exist and its data can be extracted using the getData or the various get() methods in DocumentSnapshot (such as get).

QueryDocumentSnapshot offers the same API surface as DocumentSnapshot. Since query results contain only existing documents, the exists method will always return true and getData will never be null.

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 methods

@NonNullMap<StringObject>

Returns the fields of the document as a Map.

@NonNullMap<StringObject>
getData(
    @NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the fields of the document as a Map.

@NonNull T
<T> toObject(@NonNullClass<T> valueType)

Returns the contents of the document converted to a POJO.

@NonNull T
<T> toObject(
    @NonNullClass<T> valueType,
    @NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the contents of the document converted to a POJO.

Extension functions

final @NonNull T

Returns the contents of the document converted to a POJO.

final @NonNull T
<T extends Object> FirestoreKt.toObject(
    @NonNullQueryDocumentSnapshot receiver,
    @NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the contents of the document converted to a POJO.

final @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 T
<T extends Object> FirestoreKt.toObject(
    @NonNullQueryDocumentSnapshot 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 com.google.firebase.firestore.DocumentSnapshot
boolean

Returns whether or not the field exists in the document.

boolean

Returns whether or not the field exists in the document.

boolean
boolean
@NullableObject

Returns the value at the field or null if the field doesn't exist.

@NullableObject
get(@NonNullFieldPath fieldPath)

Returns the value at the field or null if the field or document doesn't exist.

@NullableObject
get(
    @NonNullString field,
    @NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the value at the field or null if the field doesn't exist.

@Nullable T
<T> get(@NonNullString field, @NonNullClass<T> valueType)

Returns the value at the field, converted to a POJO, or null if the field or document doesn't exist.

@NullableObject
get(
    @NonNullFieldPath fieldPath,
    @NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the value at the field or null if the field or document doesn't exist.

@Nullable T
<T> get(@NonNullFieldPath fieldPath, @NonNullClass<T> valueType)

Returns the value at the field, converted to a POJO, or null if the field or document doesn't exist.

@Nullable T
<T> get(
    @NonNullString field,
    @NonNullClass<T> valueType,
    @NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the value at the field, converted to a POJO, or null if the field or document doesn't exist.

@Nullable T
<T> get(
    @NonNullFieldPath fieldPath,
    @NonNullClass<T> valueType,
    @NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the value at the field, converted to a POJO, or null if the field or document doesn't exist.

@NullableBlob

Returns the value of the field as a Blob.

@NullableBoolean

Returns the value of the field as a boolean.

@NullableDate

Returns the value of the field as a Date.

@NullableDate
getDate(
    @NonNullString field,
    @NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the value of the field as a Date.

@NullableDocumentReference

Returns the value of the field as a DocumentReference.

@NullableDouble

Returns the value of the field as a double.

@NullableGeoPoint

Returns the value of the field as a GeoPoint.

@NonNullString
@NullableLong

Returns the value of the field as a long.

@NonNullSnapshotMetadata
@NonNullDocumentReference

Gets the reference to the document.

@NullableString

Returns the value of the field as a String.

@NullableTimestamp

Returns the value of the field as a com.google.firebase.Timestamp.

@NullableTimestamp
getTimestamp(
    @NonNullString field,
    @NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the value of the field as a com.google.firebase.Timestamp.

@NullableVectorValue

Returns the value of the field as a VectorValue or null if the field does not exist in the document.

int
String

Public methods

getData

public @NonNullMap<StringObjectgetData()

Returns the fields of the document as a Map. Field values will be converted to their native Java representation.

Returns
@NonNullMap<StringObject>

The fields of the document as a Map.

getData

public @NonNullMap<StringObjectgetData(
    @NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the fields of the document as a Map. Field values will be converted to their native Java representation.

Parameters
@NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior

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

Returns
@NonNullMap<StringObject>

The fields of the document as a Map or null if the document doesn't exist.

toObject

public @NonNull T <T> toObject(@NonNullClass<T> valueType)

Returns the contents of the document converted to a POJO.

Parameters
@NonNullClass<T> valueType

The Java class to create

Returns
@NonNull T

The contents of the document in an object of type T

toObject

public @NonNull T <T> toObject(
    @NonNullClass<T> valueType,
    @NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the contents of the document converted to a POJO.

Parameters
@NonNullClass<T> valueType

The Java class to create

@NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior

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

Returns
@NonNull T

The contents of the document in an object of type T.

Extension functions

FirestoreKt.toObject

public final @NonNull T <T extends Object> FirestoreKt.toObject(@NonNullQueryDocumentSnapshot receiver)

Returns the contents of the document converted to a POJO.

Parameters
<T extends Object>

The type of the object to create.

Returns
@NonNull T

The contents of the document in an object of type T.

FirestoreKt.toObject

public final @NonNull T <T extends Object> FirestoreKt.toObject(
    @NonNullQueryDocumentSnapshot receiver,
    @NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the contents of the document converted to a POJO.

Parameters
<T extends Object>

The type of the object to create.

@NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior

Configures the behavior for server timestamps that have not yet

beensettotheirfinalvalue.
@return

The contents of the document in an object of type T.

FirestoreKt.toObject

public final @NonNull T <T extends Object> FirestoreKt.toObject(@NonNullQueryDocumentSnapshot receiver)

Returns the contents of the document converted to a POJO.

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 create.

Returns
@NonNull T

The contents of the document in an object of type T.

FirestoreKt.toObject

public final @NonNull T <T extends Object> FirestoreKt.toObject(
    @NonNullQueryDocumentSnapshot receiver,
    @NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the contents of the document converted to a POJO.

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 create.

@NonNullDocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior

Configures the behavior for server timestamps that have not yet

beensettotheirfinalvalue.
@return

The contents of the document in an object of type T.