ADocumentSnapshot contains data read from a document in your Firestoredatabase. The data can be extracted with.data() or.get(<field>) toget a specific field.

For aDocumentSnapshot that points to a non-existing document, any dataaccess will return 'undefined'. You can use theexists property toexplicitly verify a document's existence.

Type parameters

  • T

Index

Constructors

Protected constructor

Properties

exists

exists:boolean

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

id

id:string

Property of theDocumentSnapshot that provides the document's ID.

metadata

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

ref

TheDocumentReference for the document included in theDocumentSnapshot.

Methods

data

  • data(options?: SnapshotOptions):T |undefined
  • Retrieves all fields in the document as an Object. Returns 'undefined' ifthe document doesn't exist.

    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.

    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 |undefined

    An Object containing all fields in the document or 'undefined' ifthe document doesn't exist.

get

  • get(fieldPathstring |FieldPath, options?: SnapshotOptions):any
  • 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

  • isEqual(otherDocumentSnapshot<T>):boolean
  • Returns true if thisDocumentSnapshot is equal to the provided one.

    Parameters

    Returnsboolean

    true if thisDocumentSnapshot is equal to the provided one.

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.