> Documentation index: https://firebase.google.com/docs/reference/llms.txt

# QueryDocumentSnapshot


```
public class QueryDocumentSnapshot extends DocumentSnapshot
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/kotlin/java/lang/Object.html) |||
| ↳ | [com.google.firebase.firestore.DocumentSnapshot](https://firebase.google.com/docs/reference/android/com/google/firebase/firestore/DocumentSnapshot.md.txt) ||
|   | ↳ | [com.google.firebase.firestore.QueryDocumentSnapshot](https://firebase.google.com/docs/reference/android/com/google/firebase/firestore/QueryDocumentSnapshot.md.txt) |

*** ** * ** ***

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<String, Object>` | `getData()` Returns the fields of the document as a Map. |
| `@NonNull Map<String, Object>` | `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` | `<T extends Object> FirestoreKt.toObject(@NonNull QueryDocumentSnapshot receiver)` 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. |

### Inherited fields

From [com.google.firebase.firestore.DocumentSnapshot](https://firebase.google.com/docs/reference/android/com/google/firebase/firestore/DocumentSnapshot.md.txt) `final SnapshotMetadata` `metadata`

### Inherited methods

From [com.google.firebase.firestore.DocumentSnapshot](https://firebase.google.com/docs/reference/android/com/google/firebase/firestore/DocumentSnapshot.md.txt) `boolean` `contains(@NonNull String field)`

Returns whether or not the field exists in the document.
`boolean` `contains(@NonNull FieldPath fieldPath)`

Returns whether or not the field exists in the document.
`boolean` `equals(@Nullable Object obj)` `boolean` `exists()` `@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` `getBlob(@NonNull String field)`

Returns the value of the field as a `Blob`.
`@Nullable Boolean` `getBoolean(@NonNull String field)`

Returns the value of the field as a boolean.
`@Nullable BsonObjectId` `getBsonObjectId(@NonNull String field)`

Returns the value of the field as a `BsonObjectId`.
`@Nullable BsonTimestamp` `getBsonTimestamp(@NonNull String field)`

Returns the value of the field as a `BsonTimestamp`.
`@Nullable Date` `getDate(@NonNull String field)`

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 Decimal128Value` `getDecimal128Value(@NonNull String field)`

Returns the value of the field as a 128-bit decimal.
`@Nullable DocumentReference` `getDocumentReference(@NonNull String field)`

Returns the value of the field as a DocumentReference.
`@Nullable Double` `getDouble(@NonNull String field)`

Returns the value of the field as a double.
`@Nullable GeoPoint` `getGeoPoint(@NonNull String field)`

Returns the value of the field as a GeoPoint.
`@NonNull String` `getId()` `@Nullable Int32Value` `getInt32Value(@NonNull String field)`

Returns the value of the field as a 32-bit integer.
`@Nullable Long` `getLong(@NonNull String field)`

Returns the value of the field as a long.
`@Nullable MaxKey` `getMaxKey(@NonNull String field)`

Returns the value of the field as a `MaxKey`.
`@NonNull SnapshotMetadata` `getMetadata()` `@Nullable MinKey` `getMinKey(@NonNull String field)`

Returns the value of the field as a `MinKey`.
`@NonNull DocumentReference` `getReference()`

Gets the reference to the document.
`@Nullable RegexValue` `getRegexValue(@NonNull String field)`

Returns the value of the field as a `RegexValue`.
`@Nullable String` `getString(@NonNull String field)`

Returns the value of the field as a String.
`@Nullable Timestamp` `getTimestamp(@NonNull String field)`

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` `getVectorValue(@NonNull String field)`

Returns the value of the field as a `VectorValue` or `null` if the field does not exist in the document.
`int` `hashCode()` `@NonNull String` `toString()`

## Public methods

### getData

```
public @NonNull Map<String, Object> getData()
```

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

| Returns |
|---|---|
| `@NonNull Map<String, Object>` | The fields of the document as a Map. |

### getData

```
public @NonNull Map<String, Object> getData(
    @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<String, Object>` | 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. |