Firebase.Database.DataSnapshot

ADataSnapshot instance contains data from aFirebaseDatabase location.

Summary

ADataSnapshot instance contains data from aFirebaseDatabase location. Any time you readFirebaseDatabase data, you receive the data as aDataSnapshot.

DataSnapshots are passed to eventsQuery.ValueChanged

,Query.ChildChanged

,Query.ChildMoved

,Query.ChildRemoved

, orQuery.ChildAdded



They are efficiently-generated immutable copies of the data at aFirebaseDatabase location. They can't be modified and will never change. To modify data at a location, use aDatabaseReference reference (e.g. withDatabaseReference.SetValueAsync(object)

).

Properties

Children
IEnumerable<DataSnapshot >
Gives access to all of the immediate children of this Snapshot.
ChildrenCount
long
The number of immediate children in the this snapshot.
Exists
bool
Returns true if the snapshot contains a non-null value.
HasChildren
bool
Indicates whether this snapshot has any children
Key
string
The key name for the source location of this snapshot.
Priority
object
Returns the priority of the data contained in this snapshot as a native type.
Reference
Used to obtain a reference to the source location for this Snapshot.
Value
object
Value returns the data contained in this snapshot as native types.

Public functions

Child(string path)
Get aDataSnapshot for the location at the specified relative path.
GetRawJsonValue()
string
GetRawJsonValue() returns the data contained in this snapshot as a json serialized string.
GetValue(bool useExportFormat)
object
GetValue() returns the data contained in this snapshot as native types.
HasChild(string path)
bool
Can be used to determine if thisDataSnapshot has data at a particular location
ToString()
override string
A string representing theDataSnapshot as a key, value pair.

Properties

Children

IEnumerable<DataSnapshot>Children

Gives access to all of the immediate children of this Snapshot.

Gives access to all of the immediate children of this Snapshot. Can be used in native for loops:

Details
Returns
The immediate children of this snapshot

ChildrenCount

longChildrenCount

The number of immediate children in the this snapshot.

Exists

boolExists

Returns true if the snapshot contains a non-null value.

Details
Returns
True if the snapshot contains a non-null value, otherwise false

HasChildren

boolHasChildren

Indicates whether this snapshot has any children

Details
Returns
True if the snapshot has any children, otherwise false

Key

stringKey

The key name for the source location of this snapshot.

Priority

objectPriority

Returns the priority of the data contained in this snapshot as a native type.

Returns the priority of the data contained in this snapshot as a native type. Possible return types:

  • double
  • string Note that null is also allowed.

Details
Returns
the priority of the data contained in this snapshot as a native type

Reference

DatabaseReferenceReference

Used to obtain a reference to the source location for this Snapshot.

Details
Returns
ADatabaseReference corresponding to the location that this snapshot came from

Value

objectValue

Value returns the data contained in this snapshot as native types.

Value returns the data contained in this snapshot as native types. The possible types returned are:

  • bool
  • string
  • long
  • double
  • IDictionary{string, object}
  • List{object} This list is recursive; the possible types for object in the above list is given by the same list. These types correspond to the types available in JSON.

Details
Returns
The data contained in this snapshot as native types

Public functions

Child

DataSnapshotChild(stringpath)

Get aDataSnapshot for the location at the specified relative path.

Get aDataSnapshot for the location at the specified relative path. The relative path can either be a simple child key (e.g. 'fred') or a deeper slash-separated path (e.g. 'fred/name/first'). If the child location has no data, an emptyDataSnapshot is returned.

Details
Parameters
path
A relative path to the location of child data
Returns
TheDataSnapshot for the child location

GetRawJsonValue

stringGetRawJsonValue()

GetRawJsonValue() returns the data contained in this snapshot as a json serialized string.

GetRawJsonValue() returns the data contained in this snapshot as a json string.

Details
Returns
The data contained in this snapshot as json. Return null if no data.

GetValue

objectGetValue(booluseExportFormat)

GetValue() returns the data contained in this snapshot as native types.

GetValue() returns the data contained in this snapshot as native types. The possible types returned are:

  • bool
  • string
  • long
  • double
  • IDictionary{string, object}
  • List{object} This list is recursive; the possible types for object in the above list is given by the same list. These types correspond to the types available in JSON. If useExportFormat is set to true, priority information will be included in the output. Priority information shows up as a .priority key in a map. For data that would not otherwise be a map, the map will also include a .value key with the data.

Details
Parameters
useExportFormat
Whether or not to include priority information
Returns
The data, along with its priority, in native types

HasChild

boolHasChild(stringpath)

Can be used to determine if thisDataSnapshot has data at a particular location

Details
Parameters
path
A relative path to the location of child data
Returns
Whether or not the specified child location has data

ToString

overridestringToString()

A string representing theDataSnapshot as a key, value pair.

It returns the following form:DataSnapshot { key = {Key}, value = {Value} };

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2021-06-17 UTC.