docs-devsite/firestore_lite.documentsnapshot.md
Project: /docs/reference/js/_project.yaml Book: /docs/reference/_book.yaml page_type: reference
{% comment %} DO NOT EDIT THIS FILE! This is generated by the JS SDK team, and any local changes will be overwritten. Changes should be made in the source code at https://github.com/firebase/firebase-js-sdk {% endcomment %}
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.
<b>Signature:</b>
export declare class DocumentSnapshot<AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData>
| Constructor | Modifiers | Description |
|---|---|---|
| (constructor)() | Constructs a new instance of the <code>DocumentSnapshot</code> class |
| Property | Modifiers | Type | Description |
|---|---|---|---|
| id | string | Property of the <code>DocumentSnapshot</code> that provides the document's ID. | |
| ref | DocumentReference<!-- --><AppModelType, DbModelType> | The <code>DocumentReference</code> for the document included in the <code>DocumentSnapshot</code>. |
| Method | Modifiers | Description |
|---|---|---|
| data() | Retrieves all fields in the document as an <code>Object</code>. Returns <code>undefined</code> 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 <code>fieldPath</code>. Returns <code>undefined</code> if the document or field doesn't exist. |
Constructs a new instance of the DocumentSnapshot class
<b>Signature:</b>
protected constructor();
Property of the DocumentSnapshot that provides the document's ID.
<b>Signature:</b>
get id(): string;
The DocumentReference for the document included in the DocumentSnapshot<!-- -->.
<b>Signature:</b>
get ref(): DocumentReference<AppModelType, DbModelType>;
Retrieves all fields in the document as an Object<!-- -->. Returns undefined if the document doesn't exist.
<b>Signature:</b>
data(): AppModelType | undefined;
<b>Returns:</b>
AppModelType | undefined
An Object containing all fields in the document or undefined if the document doesn't exist.
Signals whether or not the document at the snapshot's location exists.
<b>Signature:</b>
exists(): this is QueryDocumentSnapshot<AppModelType, DbModelType>;
<b>Returns:</b>
this is QueryDocumentSnapshot<!-- --><AppModelType, DbModelType>
true if the document exists.
Retrieves the field specified by fieldPath<!-- -->. Returns undefined if the document or field doesn't exist.
<b>Signature:</b>
get(fieldPath: string | FieldPath): any;
| Parameter | Type | Description |
|---|---|---|
| fieldPath | string | FieldPath | The path (for example 'foo' or 'foo.bar') to a specific field. |
<b>Returns:</b>
any
The data at the specified field location or undefined if no such field exists in the document.