QueryDocumentSnapshot

class QueryDocumentSnapshot : 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 functions

(Mutable)Map<String!, Any!>

Returns the fields of the document as a Map.

(Mutable)Map<String!, Any!>
getData(
    serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior
)

Returns the fields of the document as a Map.

T
<T> toObject(valueType: Class<T!>)

Returns the contents of the document converted to a POJO.

T
<T> toObject(
    valueType: Class<T!>,
    serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior
)

Returns the contents of the document converted to a POJO.

Extension functions

inline T

Returns the contents of the document converted to a POJO.

inline T

Returns the contents of the document converted to a POJO.

inline T

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

inline T

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

Inherited functions

From com.google.firebase.firestore.DocumentSnapshot
Boolean
contains(field: String)

Returns whether or not the field exists in the document.

Boolean
contains(fieldPath: FieldPath)

Returns whether or not the field exists in the document.

Boolean
equals(obj: Any?)
Boolean
Any?
get(field: String)

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

Any?
get(fieldPath: FieldPath)

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

Any?
get(
    field: String,
    serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior
)

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

T?
<T> get(field: String, valueType: Class<T!>)

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

Any?
get(
    fieldPath: FieldPath,
    serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior
)

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

T?
<T> get(fieldPath: FieldPath, valueType: Class<T!>)

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

T?
<T> get(
    field: String,
    valueType: Class<T!>,
    serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior
)

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

T?
<T> get(
    fieldPath: FieldPath,
    valueType: Class<T!>,
    serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior
)

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

Blob?
getBlob(field: String)

Returns the value of the field as a Blob.

Boolean?

Returns the value of the field as a boolean.

Date?
getDate(field: String)

Returns the value of the field as a Date.

Date?
getDate(
    field: String,
    serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior
)

Returns the value of the field as a Date.

DocumentReference?

Returns the value of the field as a DocumentReference.

Double?
getDouble(field: String)

Returns the value of the field as a double.

GeoPoint?

Returns the value of the field as a GeoPoint.

String
Long?
getLong(field: String)

Returns the value of the field as a long.

SnapshotMetadata
DocumentReference

Gets the reference to the document.

String?
getString(field: String)

Returns the value of the field as a String.

Timestamp?

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

Timestamp?
getTimestamp(
    field: String,
    serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior
)

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

Int
String!

Public functions

getData

fun getData(): (Mutable)Map<String!, Any!>

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

Returns
(Mutable)Map<String!, Any!>

The fields of the document as a Map.

getData

fun getData(
    serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior
): (Mutable)Map<String!, Any!>

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

Parameters
serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior

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

Returns
(Mutable)Map<String!, Any!>

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

toObject

fun <T> toObject(valueType: Class<T!>): T

Returns the contents of the document converted to a POJO.

Parameters
valueType: Class<T!>

The Java class to create

Returns
T

The contents of the document in an object of type T

toObject

fun <T> toObject(
    valueType: Class<T!>,
    serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior
): T

Returns the contents of the document converted to a POJO.

Parameters
valueType: Class<T!>

The Java class to create

serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior

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

Returns
T

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

Extension functions

toObject

inline fun <T : Any> QueryDocumentSnapshot.toObject(): T

Returns the contents of the document converted to a POJO.

Parameters
<T : Any>

The type of the object to create.

Returns
T

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

toObject

inline fun <T : Any> QueryDocumentSnapshot.toObject(
    serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior
): T

Returns the contents of the document converted to a POJO.

Parameters
<T : Any>

The type of the object to create.

serverTimestampBehavior: DocumentSnapshot.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.

toObject

inline fun <T : Any> QueryDocumentSnapshot.toObject(): T

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 : Any>

The type of the object to create.

Returns
T

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

toObject

inline fun <T : Any> QueryDocumentSnapshot.toObject(
    serverTimestampBehavior: DocumentSnapshot.ServerTimestampBehavior
): T

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 : Any>

The type of the object to create.

serverTimestampBehavior: DocumentSnapshot.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.