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

INTERNAL

INTERNAL:{forceLongPolling:() =>void;forceWebSockets:() =>void }

Additional methods for debugging and special cases.

Type declaration

  • forceLongPolling:() =>void

    Force the use of long polling instead of WebSockets. This will be ignored if the WebSocket protocol is used indatabaseURL.

      • ():void
      • Returnsvoid

  • forceWebSockets:() =>void

    Force the use of WebSockets instead of long polling.

      • ():void
      • Returnsvoid

app

app:App

Theapp associated with theDatabase serviceinstance.

example
var app = database.app;

Methods

goOffline

  • goOffline():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, thegoOffline() 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, seegoOnline().

    example
    firebase.database().goOffline();

    Returnsany

goOnline

  • goOnline():any
  • Reconnects to the server and synchronizes the offline Database statewith the server state.

    This method should be used after disabling the active connection withgoOffline(). 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 aReference representing 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 returnedReference will point. If not provided, the returnedReference willpoint to the root of the Database.

    ReturnsReference

    If a path is provided, aReferencepointing to the provided path. Otherwise, aReference pointing to theroot of the Database.

refFromURL

  • refFromURL(urlstring):Reference
  • Returns aReference representing 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 currentDatabase instance.

    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 returnedReference willpoint.

    ReturnsReference

    AReference pointing to the providedFirebase URL.

useEmulator

  • useEmulator(hoststring, portnumber, 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 }

    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.