docs-devsite/firestore_pipelines.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. | |
| metadata | SnapshotMetadata | Metadata about the <code>DocumentSnapshot</code>, including information about its source and local modifications. | |
| ref | DocumentReference<!-- --><AppModelType, DbModelType> | The <code>DocumentReference</code> for the document included in the <code>DocumentSnapshot</code>. |
| Method | Modifiers | Description |
|---|---|---|
| data(options) | Retrieves all fields in the document as an <code>Object</code>. Returns <code>undefined</code> if the document doesn't exist.<!-- -->By default, <code>serverTimestamp()</code> values that have not yet been set to their final value will be returned as <code>null</code>. You can override this by passing an options object. | |
| exists() | Returns whether or not the data exists. True if the document exists. | |
| get(fieldPath, options) | Retrieves the field specified by <code>fieldPath</code>. Returns <code>undefined</code> if the document or field doesn't exist.<!-- -->By default, a <code>serverTimestamp()</code> that has not yet been set to its final value will be returned as <code>null</code>. You can override this by passing an options object. | |
| toJSON() | Returns a JSON-serializable representation of this <code>DocumentSnapshot</code> instance. |
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;
Metadata about the DocumentSnapshot<!-- -->, including information about its source and local modifications.
<b>Signature:</b>
readonly metadata: SnapshotMetadata;
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.
By default, serverTimestamp() values that have not yet been set to their final value will be returned as null<!-- -->. You can override this by passing an options object.
<b>Signature:</b>
data(options?: SnapshotOptions): AppModelType | undefined;
| Parameter | Type | Description |
|---|---|---|
| options | SnapshotOptions | An options object to configure how data is retrieved from the snapshot (for example the desired behavior for server timestamps that have not yet been set to their final value). |
<b>Returns:</b>
AppModelType | undefined
An Object containing all fields in the document or undefined if the document doesn't exist.
Returns whether or not the data exists. True if the document exists.
<b>Signature:</b>
exists(): this is QueryDocumentSnapshot<AppModelType, DbModelType>;
<b>Returns:</b>
this is QueryDocumentSnapshot<!-- --><AppModelType, DbModelType>
Retrieves the field specified by fieldPath<!-- -->. Returns undefined if the document or field doesn't exist.
By default, a serverTimestamp() that has not yet been set to its final value will be returned as null<!-- -->. You can override this by passing an options object.
<b>Signature:</b>
get(fieldPath: string | FieldPath, options?: SnapshotOptions): any;
| Parameter | Type | Description |
|---|---|---|
| fieldPath | string | FieldPath | The path (for example 'foo' or 'foo.bar') to a specific field. |
| options | SnapshotOptions | An options object to configure how the field is retrieved from the snapshot (for example the desired behavior for server timestamps that have not yet been set to their final value). |
<b>Returns:</b>
any
The data at the specified field location or undefined if no such field exists in the document.
Returns a JSON-serializable representation of this DocumentSnapshot instance.
<b>Signature:</b>
toJSON(): object;
<b>Returns:</b>
object
a JSON representation of this object. Throws a FirestoreError if this DocumentSnapshot has pending writes.