database namespace Stay organized with collections Save and categorize content based on your preferences.
Functions
| Function | Description |
|---|---|
| instance(instance) | Registers a function that triggers on events from a specific Firebase Realtime Database instance. |
| ref(path) | Registers a function that triggers on Firebase Realtime Database write events. |
Classes
| Class | Description |
|---|---|
| DataSnapshot | Interface representing a Firebase Realtime database data snapshot. |
| InstanceBuilder | The Firebase Realtime Database instance builder interface.Access via [database.instance()](providers_database_.html#instance). |
| RefBuilder | The Firebase Realtime Database reference builder interface.Access via [functions.database.ref()](functions.database#.ref). |
database.instance()
Registers a function that triggers on events from a specific Firebase Realtime Database instance.
Use this method together withref to specify the instance on which to watch for database events. For example:firebase.database.instance('my-app-db-2').ref('/foo/bar')
Note thatfunctions.database.ref used withoutinstance watches the *default* instance for events.
Signature:
exportdeclarefunctioninstance(instance:string):InstanceBuilder;Parameters
| Parameter | Type | Description |
|---|---|---|
| instance | string | The instance name of the database instance to watch for write events. |
Returns:
Firebase Realtime Database instance builder interface.
database.ref()
Registers a function that triggers on Firebase Realtime Database write events.
This method behaves very similarly to the method of the same name in the client and Admin Firebase SDKs. Any change to the Database that affects the data at or below the providedpath will fire an event in Cloud Functions.
There are three important differences between listening to a Realtime Database event in Cloud Functions and using the Realtime Database in the client and Admin SDKs:
Cloud Functions allows wildcards in the
pathname. Anypathcomponent in curly brackets ({}) is a wildcard that matches all strings. The value that matched a certain invocation of a Cloud Function is returned as part of the [EventContext.params](cloud_functions_eventcontext.html#params object. For example,ref("messages/{messageId}")matches changes at/messages/message1or/messages/message2, resulting inevent.params.messageIdbeing set to"message1"or"message2", respectively.Cloud Functions do not fire an event for data that already existed before the Cloud Function was deployed.
Cloud Function events have access to more information, including a snapshot of the previous event data and information about the user who triggered the Cloud Function.
Signature:
exportdeclarefunctionref<Refextendsstring>(path:Ref):RefBuilder<Ref>;Parameters
| Parameter | Type | Description |
|---|---|---|
| path | Ref | The path within the Database to watch for write events. |
Returns:
RefBuilder<Ref>
Firebase Realtime Database builder interface.
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 2023-04-24 UTC.