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.

Signature:

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

Properties

Property Modifiers Type Description
docs Array<QueryDocumentSnapshot<AppModelType, DbModelType>> An array of all the documents in the QuerySnapshot.
empty boolean True if there are no documents in the QuerySnapshot.
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 get or onSnapshot in order to get this QuerySnapshot.
size number The number of documents in the QuerySnapshot.

Methods

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

QuerySnapshot.docs

An array of all the documents in the QuerySnapshot.

Signature:

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

QuerySnapshot.empty

True if there are no documents in the QuerySnapshot.

Signature:

get empty(): boolean;

QuerySnapshot.metadata

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

Signature:

readonly metadata: SnapshotMetadata;

QuerySnapshot.query

The query on which you called get or onSnapshot in order to get this QuerySnapshot.

Signature:

readonly query: Query<AppModelType, DbModelType>;

QuerySnapshot.size

The number of documents in the QuerySnapshot.

Signature:

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.

Signature:

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

Parameters

Parameter Type Description
options SnapshotListenOptions SnapshotListenOptions that control whether metadata-only changes (i.e. only DocumentSnapshot.metadata changed) should trigger snapshot events.

Returns:

Array<DocumentChange<AppModelType, DbModelType>>

QuerySnapshot.forEach()

Enumerates all of the documents in the QuerySnapshot.

Signature:

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

Parameters

Parameter Type Description
callback (result: QueryDocumentSnapshot<AppModelType, DbModelType>) => void A callback to be called with a QueryDocumentSnapshot for each document in the snapshot.
thisArg unknown The this binding for the callback.

Returns:

void