Jump to top

Query

interface

A Query sorts and filters the data at a Database location so only a subset of the child data is included. This can be used to order a collection of data by some attribute (for example, height of dinosaurs) as well as to restrict a large list of items (for example, chat messages) down to a number suitable for synchronizing to the client. Queries are created by chaining together one or more of the filter methods defined here.

Just as with a Reference, you can receive data from a Query by using the on() method. You will only receive events and DataSnapshots for the subset of the data that matches your query.

Properties

ref

</>

Returns a Reference to the Query's location.

ref: Reference;

Methods

endAt

</>

Creates a Query with the specified ending point.

endAt(value: number | string | boolean | null, key?: undefined | string): Query;

equalTo

</>

Creates a Query with the specified ending point.

equalTo(value: number | string | boolean | null, key?: undefined | string): Query;

isEqual

</>

Returns whether or not the current and provided queries represent the same location, have the same query parameters.

isEqual(other: Query): boolean;

keepSynced

</>

By calling keepSynced(true) on a location, the data for that location will automatically be downloaded and kept in sync, even when no listeners are attached for that location.

keepSynced(bool: boolean): Promise<void>;

limitToFirst

</>

Generates a new Query limited to the first specific number of children.

limitToFirst(limit: number): Query;

limitToLast

</>

Generates a new Query object limited to the last specific number of children.

limitToLast(limit: number): Query;

off

</>

Detaches a callback previously attached with on().

off(eventType?: EventType, callback?: Function, context?: Record<string, any>): void;

on

</>

Listens for data changes at a particular location.

on(eventType?: EventType, callback?: Function, cancelCallbackOrContext?: Record<string, any>, context?: Record<string, any> | null): Function;

once

</>

Listens for exactly one event of the specified event type, and then stops listening.

once(eventType: EventType, successCallback?: undefined | (a: DataSnapshot, b: string | null) => any, failureCallbackContext?: (a: Error) => void | Record<string, any> | null): Promise<DataSnapshot>;

orderByChild

</>

Generates a new Query object ordered by the specified child key.

orderByChild(path: string): Query;

orderByKey

</>

Generates a new Query object ordered by key.

orderByKey(): Query;

orderByPriority

</>

Generates a new Query object ordered by priority.

orderByPriority(): Query;

orderByValue

</>

Generates a new Query object ordered by value.

orderByValue(): Query;

startAt

</>

Creates a Query with the specified starting point.

startAt(value: number | string | boolean | null, key?: undefined | string): Query;

toJSON

</>

Returns a JSON-serializable representation of this object.

toJSON(): object;

toString

</>

Gets the absolute URL for this location.

toString(): string;