Home > @firebase/firestore > lite > DocumentSnapshot
DocumentSnapshot class
A DocumentSnapshot
contains data read from a document in your Firestore database. The data can be extracted with .data()
or .get(<field>)
to get a specific field.
For a DocumentSnapshot
that points to a non-existing document, any data access will return 'undefined'. You can use the exists()
method to explicitly verify a document's existence.
Signature:
export declare class DocumentSnapshot<T = DocumentData>
Constructors
Constructor | Modifiers | Description |
---|---|---|
(constructor)() | Constructs a new instance of the DocumentSnapshot class |
Properties
Property | Modifiers | Type | Description |
---|---|---|---|
id | string | Property of the DocumentSnapshot that provides the document's ID. |
|
ref | DocumentReference<T> | The DocumentReference for the document included in the DocumentSnapshot . |
Methods
Method | Modifiers | Description |
---|---|---|
data() | Retrieves all fields in the document as an Object . Returns undefined if the document doesn't exist. |
|
exists() | Signals whether or not the document at the snapshot's location exists. | |
get(fieldPath) | Retrieves the field specified by fieldPath . Returns undefined if the document or field doesn't exist. |