Properties

adminRef

non-null admin.database.Reference

Returns a Reference to the Database location where the triggering write occurred. Similar to ref, but with full read and write access instead of end-user access.

current

non-null functions.database.DeltaSnapshot

Gets the current DeltaSnapshot after the triggering write event has occurred.

key

nullable string

The key (last part of the path) of the location of this DeltaSnapshot.

The last token in a Database location is considered its key. For example, "ada" is the key for the /users/ada/ node. Accessing the key on any DeltaSnapshot will return the key for the location that generated it. However, accessing the key on the root URL of a Database will return null.

previous

non-null functions.database.DeltaSnapshot

Gets the previous state of the DeltaSnapshot, from before the triggering write event.

ref

non-null admin.database.Reference

Returns a Reference to the Database location where the triggering write occurred. This Reference has the same end-user permissions as the client that did the write. So, if an unauthenticated client did the write, this Reference is unauthenticated. If the client that did the write is authenticated as a certain Firebase Auth user, this Reference is authenticated as that same user.

Methods

changed

changed() returns boolean

Tests whether data in the path has changed as a result of the triggered write.

See Monitoring changed values.

Returns

boolean true if any data has been modified; otherwise, false.

child

child(path) returns functions.database.DeltaSnapshot

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

The relative path can either be a simple child name (for example, "ada") or a deeper slash-separated path (for example, "ada/name/first").

Parameter

path

string

A relative path from this location to the desired child location.

Returns

non-null functions.database.DeltaSnapshot The specified child location.

exists

exists() returns boolean

Returns true if this DeltaSnapshot contains any data. It is slightly more efficient than using snapshot.val() !== null.

Returns

boolean true if this DeltaSnapshot contains any data; otherwise, false.

exportVal

exportVal() returns any type

Exports the entire contents of the DeltaSnapshot as a JavaScript object.

The exportVal() method is similar to val(), except priority information is included (if available), making it suitable for backing up your data.

Returns

any type The contents of the DeltaSnapshot as a JavaScript value (Object, Array, string, number, boolean, or null).

forEach

forEach(action) returns boolean

Enumerates the DeltaSnapshots of the children items.

Because of the way JavaScript objects work, the ordering of data in the JavaScript object returned by val() is not guaranteed to match the ordering on the server nor the ordering of child_added events. That is where forEach() comes in handy. It guarantees the children of a DeltaSnapshot will be iterated in their query order.

If no explicit orderBy*() method is used, results are returned ordered by key (unless priorities are used, in which case, results are returned by priority).

Parameter

action

function(non-null functions.database.DeltaSnapshot)

A function that will be called for each child DeltaSnapshot. The callback can return true to cancel further enumeration.

Value must not be null.

Returns

boolean true if enumeration was canceled due to your callback returning true.

getPriority

getPriority() returns (string, number, or null)

Gets the priority value of the data in this DeltaSnapshot.

As an alternative to using priority, applications can order collections by ordinary properties. See Sorting and filtering data.

Returns

(string, number, or null) The priority value of the data.

hasChild

hasChild(path) returns boolean

Returns true if the specified child path has (non-null) data.

Parameter

path

string

A relative path to the location of a potential child.

Returns

boolean true if data exists at the specified child path; else false.

hasChildren

hasChildren() returns boolean

Returns whether or not the DeltaSnapshot has any non-null child properties.

You can use hasChildren() to determine if a DeltaSnapshot has any children. If it does, you can enumerate them using forEach(). If it doesn't, then either this snapshot contains a primitive value (which can be retrieved with val()) or it is empty (in which case, val() will return null).

Returns

boolean true if this snapshot has any children; else false.

numChildren

numChildren() returns number

Returns the number of child properties of this DeltaSnapshot.

Returns

number Number of child properties of this DeltaSnapshot.

toJSON

toJSON() returns Object

Returns a JSON-serializable representation of this object.

Returns

nullable Object A JSON-serializable representation of this object.

val

val() returns any type

Extracts a JavaScript value from a DeltaSnapshot.

Depending on the data in a DeltaSnapshot, the val() method may return a scalar type (string, number, or boolean), an array, or an object. It may also return null, indicating that the DeltaSnapshot is empty (contains no data).

Returns

any type The DeltaSnapshot's contents as a JavaScript value (Object, Array, string, number, boolean, or null).