コンソールへ移動

The Cloud Firestore service interface.

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

Index

Constructors

Private constructor

Properties

app

app: App

The app associated with this Firestore service instance.

Methods

batch

  • batch(): WriteBatch
  • Creates a write batch, used for performing multiple writes as a single atomic operation. The maximum number of writes allowed in a single WriteBatch is 500, but note that each usage of FieldValue.serverTimestamp(), FieldValue.arrayUnion(), FieldValue.arrayRemove(), or FieldValue.increment() inside a WriteBatch counts as an additional write.

    Returns WriteBatch

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

clearPersistence

  • clearPersistence(): Promise<void>
  • Clears the persistent storage. This includes pending writes and cached documents.

    Must be called while the firestore instance is not started (after the app is shutdown or when the app is first initialized). On startup, this method must be called before other methods (other than settings()). If the firestore instance is still running, the promise will be rejected with the error code of failed-precondition.

    Note: clearPersistence() is primarily intended to help write reliable tests that use Firestore. It uses the most efficient mechanism possible for dropping existing data but does not attempt to securely overwrite or otherwise make cached data unrecoverable. For applications that are sensitive to the disclosure of cache data in between user sessions we strongly recommend not to enable persistence in the first place.

    Returns Promise<void>

    A promise that is resolved once the persistent storage has been cleared. Otherwise, the promise is rejected with an error.

collection

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

    Parameters

    • collectionPath: string

      A slash-separated path to a collection.

    Returns CollectionReference

    The CollectionReference instance.

collectionGroup

  • collectionGroup(collectionId: string): Query
  • Creates and returns a new Query that includes all documents in the database that are contained in a collection or subcollection with the given collectionId.

    Parameters

    • collectionId: string

      Identifies the collections to query over. Every collection or subcollection with this ID as the last segment of its path will be included. Cannot contain a slash.

    Returns Query

    The created Query.

disableNetwork

  • 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

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

    Parameters

    • documentPath: string

      A slash-separated path to a document.

    Returns DocumentReference

    The DocumentReference instance.

enableNetwork

  • 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

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

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

    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.

    Parameters

    Returns Promise<void>

    A promise that represents successfully enabling persistent storage.

runTransaction

  • 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.

    The maximum number of writes allowed in a single transaction is 500, but note that each usage of FieldValue.serverTimestamp(), FieldValue.arrayUnion(), FieldValue.arrayRemove(), or FieldValue.increment() inside a transaction counts as an additional write.

    Type parameters

    • T

    Parameters

    • updateFunction: function

      The function to execute within the transaction context.

        • Parameters

          • transact