The Cloud Firestore service interface.

Do not call this constructor directly. Instead, use firebase.firestore().



Private constructor



app: App

The app associated with this Firestore service instance.



  • batch(): WriteBatch
  • Creates a write batch, used for performing multiple writes as a single atomic operation.

    Returns WriteBatch

    A WriteBatch that can be used to atomically execute multiple writes.


  • collection(collectionPath: string): CollectionReference
  • Gets a CollectionReference instance that refers to the collection at the specified path.


    • collectionPath: string

      A slash-separated path to a collection.

    Returns CollectionReference

    The CollectionReference instance.


  • disableNetwork(): Promise<void>
  • Disables network usage for this instance. It can be re-enabled via enableNetwork(). While the network is disabled, any snapshot listeners or get() calls will return results from cache, and any write operations will be queued until the network is restored.

    Returns Promise<void>

    A promise that is resolved once the network has been disabled.


  • doc(documentPath: string): DocumentReference
  • Gets a DocumentReference instance that refers to the document at the specified path.


    • documentPath: string

      A slash-separated path to a document.

    Returns DocumentReference

    The DocumentReference instance.


  • enableNetwork(): Promise<void>
  • Re-enables use of the network for this Firestore instance after a prior call to disableNetwork().

    Returns Promise<void>

    A promise that is resolved once the network has been enabled.


  • enablePersistence(settings?: PersistenceSettings): Promise<void>
  • Attempts to enable persistent storage, if possible.

    Must be called before any other methods (other than settings()).

    If this fails, enablePersistence() will reject the promise it returns. Note that even after this failure, the firestore instance will remain usable, however offline persistence will be disabled.

    There are several reasons why this can fail, which can be identified by the code on the error.

    • failed-precondition: The app is already open in another browser tab.
    • unimplemented: The browser is incompatible with the offline persistence implementation.


    Returns Promise<void>

    A promise that represents successfully enabling persistent storage.


  • runTransaction<T>(updateFunction: function): Promise<T>
  • Executes the given updateFunction and then attempts to commit the changes applied within the transaction. If any document read within the transaction has changed, Cloud Firestore retries the updateFunction. If it fails to commit after 5 attempts, the transaction fails.

    Type parameters

    • T


    • updateFunction: function

      The function to execute within the transaction context.

    Returns Promise<T>

    If the transaction completed successfully or was explicitly aborted (the updateFunction returned a failed promise), the promise returned by the updateFunction is returned here. Else, if the transaction failed, a rejected promise with the corresponding failure error will be returned.


  • settings(settings: Settings): void
  • Specifies custom settings to be used to configure the Firestore instance. Must be set before invoking any other methods.


    • settings: Settings

      The settings to use.

    Returns void

Enviar comentarios sobre...

Si necesitas ayuda, visita nuestra página de asistencia.