The Firebase Realtime Database service interface.

Do not call this constructor directly. Instead, use admin.database().

See Introduction to the Admin Database API for a full guide on how to use the Firebase Realtime Database service.

Index

Properties

app

app: App

Methods

getRules

  • getRules(): Promise<string>
  • Gets the currently applied security rules as a string. The return value consists of the rules source including comments.

    Returns Promise<string>

    A promise fulfilled with the rules as a raw string.

getRulesJSON

  • getRulesJSON(): Promise<object>
  • Gets the currently applied security rules as a parsed JSON object. Any comments in the original source are stripped away.

    Returns Promise<object>

    A promise fulfilled with the parsed rules object.

goOffline

  • goOffline(): void
  • Disconnects from the server (all Database operations will be completed offline).

    The client automatically maintains a persistent connection to the Database server, which will remain active indefinitely and reconnect when disconnected. However, the goOffline() and goOnline() methods may be used to control the client connection in cases where a persistent connection is undesirable.

    While offline, the client will no longer receive data updates from the Database. However, all Database operations performed locally will continue to immediately fire events, allowing your application to continue behaving normally. Additionally, each operation performed locally will automatically be queued and retried upon reconnection to the Database server.

    To reconnect to the Database and begin receiving remote events, see goOnline().

    example
    admin.database().goOffline();

    Returns void

goOnline

  • goOnline(): void
  • Reconnects to the server and synchronizes the offline Database state with the server state.

    This method should be used after disabling the active connection with goOffline(). Once reconnected, the client will transmit the proper data and fire the appropriate events so that your client "catches up" automatically.

    example
    admin.database().goOnline();

    Returns void

ref

  • Returns a Reference representing the location in the Database corresponding to the provided path. Also can be invoked with an existing Reference as the argument. In that case returns a new Reference pointing to the same location. If no path argument is provided, returns a Reference that represents the root of the Database.

    example
    // Get a reference to the root of the Database
    var rootRef = admin.database.ref();
    example
    // Get a reference to the /users/ada node
    var adaRef = admin.database().ref("users/ada");
    // The above is shorthand for the following operations:
    //var rootRef = admin.database().ref();
    //var adaRef = rootRef.child("users/ada");
    example
    var adaRef = admin.database().ref("users/ada");
    // Get a new reference pointing to the same location.
    var anotherAdaRef = admin.database().ref(adaRef);

    Parameters

    • Optional path: string | Reference

      Optional path representing the location the returned Reference will point. Alternatively, a Reference object to copy. If not provided, the returned Reference will point to the root of the Database.

    Returns Reference

    If a path is provided, a Reference pointing to the provided path. Otherwise, a Reference pointing to the root of the Database.

refFromURL

  • Returns a Reference representing the location in the Database corresponding to the provided Firebase URL.

    An exception is thrown if the URL is not a valid Firebase Database URL or it has a different domain than the current Database instance.

    Note that all query parameters (orderBy, limitToLast, etc.) are ignored and are not applied to the returned Reference.

    example
    // Get a reference to the root of the Database
    var rootRef = admin.database().ref("https://<DATABASE_NAME>.firebaseio.com");
    example
    // Get a reference to the /users/ada node
    var adaRef = admin.database().ref("https://<DATABASE_NAME>.firebaseio.com/users/ada");

    Parameters

    • url: string

      The Firebase URL at which the returned Reference will point.

    Returns Reference

    A Reference pointing to the provided Firebase URL.

setRules

  • setRules(source: string | Buffer | object): Promise<void>
  • Sets the specified rules on the Firebase Realtime Database instance. If the rules source is specified as a string or a Buffer, it may include comments.

    Parameters

    • source: string | Buffer | object

      Source of the rules to apply. Must not be null or empty.

    Returns Promise<void>

    Resolves when the rules are set on the Realtime Database.