Back to Firebase Js Sdk

QuerySnapshot class

docs-devsite/firestore_.querysnapshot.md

12.12.15.2 KB
Original Source

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 %}

QuerySnapshot class

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>

typescript
export declare class QuerySnapshot<AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData> 

Properties

PropertyModifiersTypeDescription
docsArray<QueryDocumentSnapshot<!-- --><AppModelType, DbModelType>>An array of all the documents in the <code>QuerySnapshot</code>.
emptybooleanTrue if there are no documents in the <code>QuerySnapshot</code>.
metadataSnapshotMetadataMetadata about this snapshot, concerning its source and if it has local modifications.
queryQuery<!-- --><AppModelType, DbModelType>The query on which you called <code>get</code> or <code>onSnapshot</code> in order to get this <code>QuerySnapshot</code>.
sizenumberThe number of documents in the <code>QuerySnapshot</code>.

Methods

MethodModifiersDescription
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.

QuerySnapshot.docs

An array of all the documents in the QuerySnapshot<!-- -->.

<b>Signature:</b>

typescript
get docs(): Array<QueryDocumentSnapshot<AppModelType, DbModelType>>;

QuerySnapshot.empty

True if there are no documents in the QuerySnapshot<!-- -->.

<b>Signature:</b>

typescript
get empty(): boolean;

QuerySnapshot.metadata

Metadata about this snapshot, concerning its source and if it has local modifications.

<b>Signature:</b>

typescript
readonly metadata: SnapshotMetadata;

QuerySnapshot.query

The query on which you called get or onSnapshot in order to get this QuerySnapshot<!-- -->.

<b>Signature:</b>

typescript
readonly query: Query<AppModelType, DbModelType>;

QuerySnapshot.size

The number of documents in the QuerySnapshot<!-- -->.

<b>Signature:</b>

typescript
get size(): number;

QuerySnapshot.docChanges()

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>

typescript
docChanges(options?: SnapshotListenOptions): Array<DocumentChange<AppModelType, DbModelType>>;

Parameters

ParameterTypeDescription
optionsSnapshotListenOptions<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>>

QuerySnapshot.forEach()

Enumerates all of the documents in the QuerySnapshot<!-- -->.

<b>Signature:</b>

typescript
forEach(callback: (result: QueryDocumentSnapshot<AppModelType, DbModelType>) => void, thisArg?: unknown): void;

Parameters

ParameterTypeDescription
callback(result: QueryDocumentSnapshot<!-- --><AppModelType, DbModelType>) => voidA callback to be called with a <code>QueryDocumentSnapshot</code> for each document in the snapshot.
thisArgunknownThe <code>this</code> binding for the callback.

<b>Returns:</b>

void

QuerySnapshot.toJSON()

Returns a JSON-serializable representation of this QuerySnapshot instance.

<b>Signature:</b>

typescript
toJSON(): object;

<b>Returns:</b>

object

a JSON representation of this object. Throws a FirestoreError if this QuerySnapshot has pending writes.