Firebase.Database.DatabaseReference

A Firebase reference represents a particular location in your FirebaseDatabase and can be used for reading or writing data to that FirebaseDatabase location.

Summary

A Firebase reference represents a particular location in your FirebaseDatabase and can be used for reading or writing data to that FirebaseDatabase location. This class is the starting point for all Database operations. After you've initialized it with a URL, you can use it to read data, write data, and to create mores instances of DatabaseReference.

Inheritance

Inherits from: Firebase.Database.Query

Properties

Database
Gets the Database instance associated with this reference.
Key
string
The last token in the location pointed to by this reference
Parent
A DatabaseReference to the parent location, or null if this instance references the root location.
Root
A reference to the root location of this FirebaseDatabase.

Public functions

Child(string pathString)
Get a reference to location relative to this one
Equals(object other)
override bool
Returns true if both objects reference the same database path.
GetHashCode()
override int
A hash code based on the string path of the reference.
OnDisconnect()
Provides access to disconnect operations at this location
Push()
Create a reference to an auto-generated child location.
RemoveValueAsync()
Task
Set the value at this location to 'null'
RunTransaction(Func< MutableData, TransactionResult > transaction)
Task< DataSnapshot >
Run a transaction on the data at this location.
RunTransaction(Func< MutableData, TransactionResult > transaction, bool fireLocalEvents)
Task< DataSnapshot >
Run a transaction on the data at this location.
SetPriorityAsync(object priority)
Task
Set a priority for the data at this Database location.
SetRawJsonValueAsync(string jsonValue)
Task
Set the data at this location to the given string json represenation.
SetRawJsonValueAsync(string jsonValue, object priority)
Task
Set the data and priority to the given values.
SetValueAsync(object value)
Task
Set the data at this location to the given value.
SetValueAsync(object value, object priority)
Task
Set the data and priority to the given values.
ToString()
override string
The full location url for this reference.
UpdateChildrenAsync(IDictionary< string, object > update)
Task
Update the specific child keys to the specified values.

Public static functions

GoOffline()
void
Manually disconnect the FirebaseDatabase client from the server and disable automatic reconnection.
GoOnline()
void
Manually reestablish a connection to the FirebaseDatabase server and enable automatic reconnection.

Properties

Database

FirebaseDatabase Database

Gets the Database instance associated with this reference.

Details
Returns
The Database object for this reference.

Key

string Key

The last token in the location pointed to by this reference

Parent

DatabaseReference Parent

A DatabaseReference to the parent location, or null if this instance references the root location.

Root

DatabaseReference Root

A reference to the root location of this FirebaseDatabase.

Public functions

Child

DatabaseReference Child(
  string pathString
)

Get a reference to location relative to this one

Details
Parameters
pathString
The relative path from this reference to the new one that should be created
Returns
A new DatabaseReference to the given path

Equals

override bool Equals(
  object other
)

Returns true if both objects reference the same database path.

GetHashCode

override int GetHashCode()

A hash code based on the string path of the reference.

OnDisconnect

OnDisconnect OnDisconnect()

Provides access to disconnect operations at this location

Details
Returns
An object for managing disconnect operations at this location

Push

DatabaseReference Push()

Create a reference to an auto-generated child location.

Create a reference to an auto-generated child location. The child key is generated client-side and incorporates an estimate of the server's time for sorting purposes. Locations generated on a single client will be sorted in the order that they are created, and will be sorted approximately in order across all clients.

Details
Returns
A DatabaseReference pointing to the new location

RemoveValueAsync

Task RemoveValueAsync()

Set the value at this location to 'null'

Details
Returns
The Task{TResult} for this operation.

RunTransaction

Task< DataSnapshot > RunTransaction(
  Func< MutableData, TransactionResult > transaction
)

Run a transaction on the data at this location.

A transaction is a data transformation function that is continually attempted until the DatabaseReference location remains unchanged during the operation.

Details
Parameters
transaction
A function to perform the transaction and return a result

RunTransaction

Task< DataSnapshot > RunTransaction(
  Func< MutableData, TransactionResult > transaction,
  bool fireLocalEvents
)

Run a transaction on the data at this location.

A transaction is a data transformation function that is continually attempted until the DatabaseReference location remains unchanged during the operation.

Details
Parameters
transaction
A function to perform the transaction and return a result
fireLocalEvents
Defaults to true. If set to false, events will only be fired for the final result state of the transaction, and not for any intermediate states

SetPriorityAsync

Task SetPriorityAsync(
  object priority
)

Set a priority for the data at this Database location.

Set a priority for the data at this Database location. Priorities can be used to provide a custom ordering for the children at a location (if no priorities are specified, the children are ordered by key).

You cannot set a priority on an empty location. For this reason setValue(data, priority) should be used when setting initial data with a specific priority and setPriority should be used when updating the priority of existing data.

Children are sorted based on this priority using the following rules:

  • Children with no priority come first.
  • Children with a number as their priority come next. They are sorted numerically by priority (small to large).
  • Children with a string as their priority come last. They are sorted lexicographically by priority.
  • Whenever two children have the same priority (including no priority), they are sorted by key. Numeric keys come first (sorted numerically), followed by the remaining keys (sorted lexicographically).
Note that numerical priorities are parsed and ordered as IEEE 754 double-precision floating-point numbers. Keys are always stored as strings and are treated as numeric only when they can be parsed as a 32-bit integer.

Details
Parameters
priority
The priority to set at the specified location.
Returns
The Task{TResult} for this operation.

SetRawJsonValueAsync

Task SetRawJsonValueAsync(
  string jsonValue
)

Set the data at this location to the given string json represenation.

Details
Returns
The Task{TResult} for this operation.

SetRawJsonValueAsync

Task SetRawJsonValueAsync(
  string jsonValue,
  object priority
)

Set the data and priority to the given values.

Details
Returns
The Task{TResult} for this operation.

SetValueAsync

Task SetValueAsync(
  object value
)

Set the data at this location to the given value.

Set the data at this location to the given value. Passing null to setValue() will delete the data at the specified location. The allowed types are:

  • bool
  • string
  • long
  • double
  • IDictionary{string, object}
  • List{object}

Details
Parameters
value
The value to set at this location
Returns
The Task{TResult} for this operation.

SetValueAsync

Task SetValueAsync(
  object value,
  object priority
)

Set the data and priority to the given values.

Set the data and priority to the given values. Passing null to setValue() will delete the data at the specified location. The allowed types are:

  • bool
  • string
  • long
  • double
  • IDictionary{string, object}
  • List{object}

Details
Parameters
value
The value to set at this location
priority
The priority to set at this location
Returns
The Task{TResult} for this operation.

ToString

override string ToString()

The full location url for this reference.

UpdateChildrenAsync

Task UpdateChildrenAsync(
  IDictionary< string, object > update
)

Update the specific child keys to the specified values.

Update the specific child keys to the specified values. Passing null in a map to updateChildren() will Remove the value at the specified location.

Details
Parameters
update
The paths to update and their new values
Returns
The Task{TResult} for this operation.

Public static functions

GoOffline

void GoOffline()

Manually disconnect the FirebaseDatabase client from the server and disable automatic reconnection.

Manually disconnect the FirebaseDatabase client from the server and disable automatic reconnection. Note: Invoking this method will impact all FirebaseDatabase connections.

GoOnline

void GoOnline()

Manually reestablish a connection to the FirebaseDatabase server and enable automatic reconnection.

Manually reestablish a connection to the FirebaseDatabase server and enable automatic reconnection. Note: Invoking this method will impact all FirebaseDatabase connections.