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

@NonNull Map<StringObject>

Returns the fields of the document as a Map.

@NonNull Map<StringObject>
getData(
    @NonNull DocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the fields of the document as a Map.

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

Returns the contents of the document converted to a POJO.

@NonNull T
<T> toObject(
    @NonNull Class<T> valueType,
    @NonNull DocumentSnapshot.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(
    @NonNull QueryDocumentSnapshot receiver,
    @NonNull DocumentSnapshot.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(
    @NonNull QueryDocumentSnapshot 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 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
@Nullable Object
get(@NonNull String field)

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

@Nullable Object
get(@NonNull FieldPath fieldPath)

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

@Nullable Object
get(
    @NonNull String field,
    @NonNull DocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

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

@Nullable T
<T> get(@NonNull String field, @NonNull Class<T> valueType)

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

@Nullable Object
get(
    @NonNull FieldPath fieldPath,
    @NonNull DocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

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

@Nullable T
<T> get(@NonNull FieldPath fieldPath, @NonNull Class<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(
    @NonNull String field,
    @NonNull Class<T> valueType,
    @NonNull DocumentSnapshot.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(
    @NonNull FieldPath fieldPath,
    @NonNull Class<T> valueType,
    @NonNull DocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

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

@Nullable Blob

Returns the value of the field as a Blob.

@Nullable Boolean

Returns the value of the field as a boolean.

@Nullable Date

Returns the value of the field as a Date.

@Nullable Date
getDate(
    @NonNull String field,
    @NonNull DocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the value of the field as a Date.

@Nullable DocumentReference

Returns the value of the field as a DocumentReference.

@Nullable Double

Returns the value of the field as a double.

@Nullable GeoPoint

Returns the value of the field as a GeoPoint.

@NonNull String
@Nullable Long

Returns the value of the field as a long.

@NonNull SnapshotMetadata
@NonNull DocumentReference

Gets the reference to the document.

@Nullable String

Returns the value of the field as a String.

@Nullable Timestamp

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

@Nullable Timestamp
getTimestamp(
    @NonNull String field,
    @NonNull DocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

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

@Nullable VectorValue

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 @NonNull Map<StringObjectgetData()

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

Returns
@NonNull Map<StringObject>

The fields of the document as a Map.

getData

public @NonNull Map<StringObjectgetData(
    @NonNull DocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

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

Parameters
@NonNull DocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior

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

Returns
@NonNull Map<StringObject>

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

toObject

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

Returns the contents of the document converted to a POJO.

Parameters
@NonNull Class<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(
    @NonNull Class<T> valueType,
    @NonNull DocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the contents of the document converted to a POJO.

Parameters
@NonNull Class<T> valueType

The Java class to create

@NonNull DocumentSnapshot.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(@NonNull QueryDocumentSnapshot 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(
    @NonNull QueryDocumentSnapshot receiver,
    @NonNull DocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior
)

Returns the contents of the document converted to a POJO.

Parameters
<T extends Object>

The type of the object to create.

@NonNull DocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior

Configures the behavior for server timestamps that have not yet

        been set to their final value.
@return

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

FirestoreKt.toObject

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

@NonNull DocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior

Configures the behavior for server timestamps that have not yet

        been set to their final value.
@return

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