The Firebase Database service interface.
Do not call this constructor directly. Instead, usefirebase.database().
See Installation & Setup in JavaScriptfor a full guide on how to use the Firebase Database service.
Index
Properties
Methods
Properties
INTERNAL
Additional methods for debugging and special cases.
Type declaration
force
Long Polling:() =>void Force the use of long polling instead of WebSockets. This will be ignored if the WebSocket protocol is used in
databaseURL.- ():void
Returnsvoid
force
Web Sockets:() =>void Force the use of WebSockets instead of long polling.
- ():void
Returnsvoid
app
Theapp associated with theDatabase serviceinstance.
- example
var app = database.app;
Methods
goOffline
- go
Offline():any Disconnects from the server (all Database operations will be completedoffline).
The client automatically maintains a persistent connection to the Databaseserver, which will remain active indefinitely and reconnect whendisconnected. However, the
goOffline()andgoOnline()methods may be usedto control the client connection in cases where a persistent connection isundesirable.While offline, the client will no longer receive data updates from theDatabase. However, all Database operations performed locally will continue toimmediately fire events, allowing your application to continue behavingnormally. Additionally, each operation performed locally will automaticallybe queued and retried upon reconnection to the Database server.
To reconnect to the Database and begin receiving remote events, see
goOnline().- example
firebase.database().goOffline();
Returnsany
goOnline
- go
Online():any Reconnects to the server and synchronizes the offline Database statewith the server state.
This method should be used after disabling the active connection with
goOffline(). Once reconnected, the client will transmit the proper dataand fire the appropriate events so that your client "catches up"automatically.- example
firebase.database().goOnline();
Returnsany
ref
- ref(path?: string):Reference
Returns a
Referencerepresenting the location in the Databasecorresponding to the provided path. If no path is provided, theReferencewill point to the root of the Database.- example
// Get a reference to the root of the Databasevar rootRef = firebase.database().ref();- example
// Get a reference to the /users/ada nodevar adaRef = firebase.database().ref("users/ada");// The above is shorthand for the following operations://var rootRef = firebase.database().ref();//var adaRef = rootRef.child("users/ada");
Parameters
Optional path:string
Optional path representing the location the returned
Referencewill point. If not provided, the returnedReferencewillpoint to the root of the Database.
ReturnsReference
If a path is provided, a
Referencepointing to the provided path. Otherwise, aReferencepointing to theroot of the Database.
refFromURL
- ref
FromURL(url: string):Reference Returns a
Referencerepresenting the location in the Databasecorresponding to the provided Firebase URL.An exception is thrown if the URL is not a valid Firebase Database URL or ithas a different domain than the current
Databaseinstance.Note that all query parameters (
orderBy,limitToLast, etc.) are ignoredand are not applied to the returnedReference.- example
// Get a reference to the root of the Databasevar rootRef = firebase.database().ref("https://<DATABASE_NAME>.firebaseio.com");- example
// Get a reference to the /users/ada nodevar adaRef = firebase.database().ref("https://<DATABASE_NAME>.firebaseio.com/users/ada");
Parameters
url:string
The Firebase URL at which the returned
Referencewillpoint.
ReturnsReference
A
Referencepointing to the providedFirebase URL.
useEmulator
- use
Emulator(host: string, port: number, options?: {mockUserToken?:EmulatorMockTokenOptions |string }):void Modify this instance to communicate with the Realtime Database emulator.
Note: This method must be called before performing any other operation.
Parameters
host:string
the emulator host (ex: localhost)
port:number
the emulator port (ex: 8080)
Optional options:{mockUserToken?:EmulatorMockTokenOptions |string }
Optional mock
User Token?:EmulatorMockTokenOptions |string the mock auth token to use for unit testing Security Rules
Returnsvoid
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 2022-07-27 UTC.