Back to Firebase Js Sdk

QuerySnapshot class

docs-devsite/firestore_lite.querysnapshot.md

12.12.13.3 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>.
queryQuery<!-- --><AppModelType, DbModelType>The query on which you called getDocs() in order to get this <code>QuerySnapshot</code>.
sizenumberThe number of documents in the <code>QuerySnapshot</code>.

Methods

MethodModifiersDescription
forEach(callback, thisArg)Enumerates all of the documents in the <code>QuerySnapshot</code>.

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

The query on which you called getDocs() 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.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