A DataSnapshot is an immutable representation of data at a specific location and point in time. Snapshots are returned by read operations such as once(), get(), and on() callbacks.
Properties
Methods
val
Returns the data contained in this snapshot as a JavaScript value (object, array, string, number, boolean, or null). Priority metadata (.priority) is stripped from the result.
Returns null if no data exists at this location.
exists
Returns true if this snapshot contains data (i.e., val() would return something other than null).
hasChildren
Returns true if this snapshot has any child properties.
hasChild
Returns true if a child exists at the specified relative path.
numChildren
Returns the number of immediate children of this snapshot.
child
Returns a DataSnapshot for a child location relative to this snapshot.
forEach
Iterates over each direct child of this snapshot in sorted order. If the callback returns true, iteration stops early.
Children are iterated in their sort order. If the snapshot was produced by a query with an orderBy clause, forEach respects that ordering.
getPriority
Returns the priority of the data at this location, or null if no priority is set.
exportVal
Returns the data including priority metadata (.priority and .value fields). Useful for serialization or backup scenarios where priority information must be preserved.
toJSON
Returns the same result as exportVal(). Provided for compatibility with JSON.stringify().
isVolatile
Returns true if this snapshot was produced by a high-frequency volatile update. Volatile snapshots are delivered outside the normal consistency model for low-latency use cases such as cursor positions or live indicators.
getServerTimestamp
Returns the server timestamp (in milliseconds since the Unix epoch) associated with this snapshot, or null if not available. Primarily useful for volatile snapshots to determine when the update was generated on the server.