Jump to top

Reference

interface

A Reference represents a specific location in your Database and can be used for reading or writing data to that Database location.

You can reference the root or child location in your Database by calling firebase.database().ref() or firebase.database().ref("child/path").

Properties

key

</>

The last part of the Reference's path. For example, "ada" is the key for https://<DATABASE_NAME>.firebaseio.com/users/ada. The key of a root Reference is null.

key: string | null;

parent

</>

The parent location of a Reference. The parent of a root Reference is null.

parent: Reference | null;

ref

</>

Returns a Reference to the Query's location.

ref: Reference;

root

</>

The root Reference of the Database.

root: Reference;

Methods

child

</>

Gets a Reference for the location at the specified relative path.

child(path: string): Reference;

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;

onDisconnect

</>

Returns an OnDisconnect instance.

onDisconnect(): OnDisconnect;

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;

push

</>

Generates a new child location using a unique key and returns its Reference.

push(value?: any, onComplete?: Function): ThenableReference;

remove

</>

Removes the data at this Database location.

remove(onComplete?: Function): Promise<void>;

set

</>

Writes data to this Database location.

set(value: any, onComplete?: Function): Promise<void>;

setPriority

</>

Sets a priority for the data at this Database location. Setting null removes any priority at this location.

setPriority(priority: string | number | null, onComplete?: Function): Promise<void>;

setWithPriority

</>

Writes data the Database location. Like set() but also specifies the priority for that data.

setWithPriority(newVal: any, newPriority: string | number | null, onComplete?: Function): Promise<void>;

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;

transaction

</>

Atomically modifies the data at this location.

transaction(transactionUpdate: Function, onComplete?: Function, applyLocally?: undefined | false | true): Promise<TransactionResult>;

update

</>

Writes multiple values to the Database at once.

update(values: { [key: string]: value }, onComplete?: Function): Promise<void>;