AQueryDocumentSnapshot contains data read from a document in yourFirestore database as part of a query. The document is guaranteed to existand its data can be extracted with.data() or.get(<field>) to get aspecific field.

AQueryDocumentSnapshot offers the same API surface as aDocumentSnapshot. Since query results contain only existing documents, theexists property will always be true anddata() will never return'undefined'.

Type parameters

  • T

Index

Constructors

Private constructor

Properties

exists

exists:boolean

Inherited fromDocumentSnapshot.exists

Property of theDocumentSnapshot that signals whether or not the dataexists. True if the document exists.

id

id:string

Inherited fromDocumentSnapshot.id

Property of theDocumentSnapshot that provides the document's ID.

metadata

Inherited fromDocumentSnapshot.metadata

Metadata about theDocumentSnapshot, including information about itssource and local modifications.

ref

Inherited fromDocumentSnapshot.ref

TheDocumentReference for the document included in theDocumentSnapshot.

Methods

data

  • data(options?: SnapshotOptions):T
  • OverridesDocumentSnapshot.data

    Retrieves all fields in the document as an Object.

    By default,FieldValue.serverTimestamp() values that have not yet beenset to their final value will be returned asnull. You can overridethis by passing an options object.

    override

    Parameters

    • Optional options:SnapshotOptions

      An options object to configure how data is retrieved fromthe snapshot (e.g. the desired behavior for server timestamps that havenot yet been set to their final value).

    ReturnsT

    An Object containing all fields in the document.

get

  • get(fieldPathstring |FieldPath, options?: SnapshotOptions):any
  • Inherited fromDocumentSnapshot.get

    Retrieves the field specified byfieldPath. Returnsundefined if thedocument or field doesn't exist.

    By default, aFieldValue.serverTimestamp() that has not yet been set toits final value will be returned asnull. You can override this bypassing an options object.

    Parameters

    • fieldPath:string |FieldPath

      The path (e.g. 'foo' or 'foo.bar') to a specific field.

    • Optional options:SnapshotOptions

      An options object to configure how the field is retrievedfrom the snapshot (e.g. the desired behavior for server timestamps that havenot yet been set to their final value).

    Returnsany

    The data at the specified field location or undefined if no suchfield exists in the document.

isEqual

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2022-07-27 UTC.