docs-devsite/firestore_.querysnapshot.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 QuerySnapshot contains zero or more DocumentSnapshot objects representing the results of a query. The documents can be accessed as an array via the docs property or enumerated using the forEach method. The number of documents can be determined via the empty and size properties.
<b>Signature:</b>
export declare class QuerySnapshot<AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData>
| Property | Modifiers | Type | Description |
|---|---|---|---|
| docs | Array<QueryDocumentSnapshot<!-- --><AppModelType, DbModelType>> | An array of all the documents in the <code>QuerySnapshot</code>. | |
| empty | boolean | True if there are no documents in the <code>QuerySnapshot</code>. | |
| metadata | SnapshotMetadata | Metadata about this snapshot, concerning its source and if it has local modifications. | |
| query | Query<!-- --><AppModelType, DbModelType> | The query on which you called <code>get</code> or <code>onSnapshot</code> in order to get this <code>QuerySnapshot</code>. | |
| size | number | The number of documents in the <code>QuerySnapshot</code>. |
| Method | Modifiers | Description |
|---|---|---|
| docChanges(options) | Returns an array of the documents changes since the last snapshot. If this is the first snapshot, all documents will be in the list as 'added' changes. | |
| forEach(callback, thisArg) | Enumerates all of the documents in the <code>QuerySnapshot</code>. | |
| toJSON() | Returns a JSON-serializable representation of this <code>QuerySnapshot</code> instance. |
An array of all the documents in the QuerySnapshot<!-- -->.
<b>Signature:</b>
get docs(): Array<QueryDocumentSnapshot<AppModelType, DbModelType>>;
True if there are no documents in the QuerySnapshot<!-- -->.
<b>Signature:</b>
get empty(): boolean;
Metadata about this snapshot, concerning its source and if it has local modifications.
<b>Signature:</b>
readonly metadata: SnapshotMetadata;
The query on which you called get or onSnapshot in order to get this QuerySnapshot<!-- -->.
<b>Signature:</b>
readonly query: Query<AppModelType, DbModelType>;
The number of documents in the QuerySnapshot<!-- -->.
<b>Signature:</b>
get size(): number;
Returns an array of the documents changes since the last snapshot. If this is the first snapshot, all documents will be in the list as 'added' changes.
<b>Signature:</b>
docChanges(options?: SnapshotListenOptions): Array<DocumentChange<AppModelType, DbModelType>>;
| Parameter | Type | Description |
|---|---|---|
| options | SnapshotListenOptions | <code>SnapshotListenOptions</code> that control whether metadata-only changes (i.e. only <code>DocumentSnapshot.metadata</code> changed) should trigger snapshot events. |
<b>Returns:</b>
Array<DocumentChange<!-- --><AppModelType, DbModelType>>
Enumerates all of the documents in the QuerySnapshot<!-- -->.
<b>Signature:</b>
forEach(callback: (result: QueryDocumentSnapshot<AppModelType, DbModelType>) => void, thisArg?: unknown): void;
| Parameter | Type | Description |
|---|---|---|
| callback | (result: QueryDocumentSnapshot<!-- --><AppModelType, DbModelType>) => void | A callback to be called with a <code>QueryDocumentSnapshot</code> for each document in the snapshot. |
| thisArg | unknown | The <code>this</code> binding for the callback. |
<b>Returns:</b>
void
Returns a JSON-serializable representation of this QuerySnapshot instance.
<b>Signature:</b>
toJSON(): object;
<b>Returns:</b>
object
a JSON representation of this object. Throws a FirestoreError if this QuerySnapshot has pending writes.