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
- new
Document Snapshot():DocumentSnapshot ReturnsDocumentSnapshot
Properties
exists
Property of theDocumentSnapshot that signals whether or not the dataexists. True if the document exists.
id
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(fieldPath: string |FieldPath, options?: SnapshotOptions):any
Retrieves the field specified by
fieldPath. Returnsundefinedif thedocument or field doesn't exist.By default, a
FieldValue.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
- is
Equal(other: DocumentSnapshot<T>):boolean Returns true if this
DocumentSnapshotis equal to the provided one.Parameters
other:DocumentSnapshot<T>
The
DocumentSnapshotto compare against.
Returnsboolean
true if this
DocumentSnapshotis 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.