Jump to top

Query

interface

A Query refers to a Query which you can read or listen to. You can also construct refined Query objects by adding filters and ordering.

Methods

count

</>

Calculates the number of documents in the result set of the given query, without actually downloading the documents.

count(): AggregateQuery<{ count: AggregateField<number> }>;

countFromServer

</>

Same as count()

countFromServer(): AggregateQuery<{ count: AggregateField<number> }>;

endAt

</>
Signature 1
</>

Creates and returns a new Query that ends at the provided document (inclusive). The end position is relative to the order of the query. The document must contain all of the fields provided in the orderBy of this query.

endAt(snapshot: DocumentSnapshot<>): Query<>;
Signature 2
</>

Creates and returns a new Query that ends at the provided fields relative to the order of the query. The order of the field values must match the order of the order by clauses of the query.

endAt(fieldValues: any[]): Query<>;

endBefore

</>
Signature 1
</>

Creates and returns a new Query that ends before the provided document (exclusive). The end position is relative to the order of the query. The document must contain all of the fields provided in the orderBy of this query.

endBefore(snapshot: DocumentSnapshot<>): Query<>;
Signature 2
</>

Creates and returns a new Query that ends before the provided fields relative to the order of the query. The order of the field values must match the order of the order by clauses of the query.

endBefore(fieldValues: any[]): Query<>;

get

</>

Executes the query and returns the results as a QuerySnapshot.

get(options?: GetOptions): Promise<QuerySnapshot<>>;

isEqual

</>

Returns true if this Query is equal to the provided one.

isEqual(other: Query): boolean;

limit

</>

Creates and returns a new Query where the results are limited to the specified number of documents.

limit(limit: number): Query<>;

limitToLast

</>

Creates and returns a new Query where the results are limited to the specified number of documents starting from the last document. The order is dependent on the second parameter for the orderBy method. If desc is used, the order is reversed. orderBy method call is required when calling limitToLast.

limitToLast(limitToLast: number): Query<>;

onSnapshot

</>
Signature 1
</>

Attaches a listener for QuerySnapshot events.

onSnapshot(observer: { complete: undefined | () => void, error: undefined | (error: Error) => void, next: undefined | (snapshot: QuerySnapshot<>) => void }): () => void;
Signature 2
</>

Attaches a listener for QuerySnapshot events with snapshot listener options.

onSnapshot(options: SnapshotListenOptions, observer: { complete: undefined | () => void, error: undefined | (error: Error) => void, next: undefined | (snapshot: QuerySnapshot<>) => void }): () => void;
Signature 3
</>

Attaches a listener for QuerySnapshot events.

onSnapshot(onNext: (snapshot: QuerySnapshot<>) => void, onError?: undefined | (error: Error) => void, onCompletion?: undefined | () => void): () => void;
Signature 4
</>

Attaches a listener for QuerySnapshot events with snapshot listener options.

onSnapshot(options: SnapshotListenOptions, onNext: (snapshot: QuerySnapshot<>) => void, onError?: undefined | (error: Error) => void, onCompletion?: undefined | () => void): () => void;

orderBy

</>

Creates and returns a new Query that's additionally sorted by the specified field, optionally in descending order instead of ascending.

orderBy(fieldPath:  | string | FieldPath, directionStr?: "asc" | "desc"): Query<>;

startAfter

</>
Signature 1
</>

Creates and returns a new Query that starts after the provided document (exclusive). The start position is relative to the order of the query. The document must contain all of the fields provided in the orderBy of this query.

startAfter(snapshot: DocumentSnapshot<>): Query<>;
Signature 2
</>

Creates and returns a new Query that starts after the provided fields relative to the order of the query. The order of the field values must match the order of the order by clauses of the query.

startAfter(fieldValues: any[]): Query<>;

startAt

</>
Signature 1
</>

Creates and returns a new Query that starts at the provided document (inclusive). The start position is relative to the order of the query. The document must contain all of the fields provided in the orderBy of this query.

startAt(snapshot: DocumentSnapshot<>): Query<>;
Signature 2
</>

Creates and returns a new Query that starts at the provided fields relative to the order of the query. The order of the field values must match the order of the order by clauses of the query.

startAt(fieldValues: any[]): Query<>;

where

</>
Signature 1
</>

Creates and returns a new Query with the additional filter that documents must contain the specified field and the value should satisfy the relation constraint provided.

where(fieldPath:  | FieldPath, opStr: WhereFilterOp, value: any): Query<>;
Signature 2
</>

Creates and returns a new Query with the additional filter that documents must contain the specified field and the value should satisfy the relation constraint provided.