Jump to top

firestore

interface

The Firebase Cloud Firestore service is available for the default app or a given app.

Example: Get the firestore instance for the default app:
const firestoreForDefaultApp = firebase.firestore();
Example: Get the firestore instance for a secondary app:
const otherApp = firebase.app('otherApp');
const firestoreForOtherApp = firebase.firestore(otherApp);

Properties

app

</>

The current FirebaseApp instance for this Firebase service.

app: FirebaseApp;

Methods

batch

</>

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.

batch(): WriteBatch;

clearPersistence

</>

Aimed primarily at clearing up any data cached from running tests. Needs to be executed before any database calls are made.

clearPersistence(): Promise<void>;

collection

</>

Gets a CollectionReference instance that refers to the collection at the specified path.

collection(collectionPath: string): CollectionReference;

collectionGroup

</>

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.

collectionGroup(collectionId: string): Query;

disableNetwork

</>

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.

disableNetwork(): Promise<void>;

doc

</>

Gets a DocumentReference instance that refers to the document at the specified path.

doc(documentPath: string): DocumentReference;

enableNetwork

</>

Re-enables use of the network for this Firestore instance after a prior call to disableNetwork().

enableNetwork(): Promise<void>;

runTransaction

</>

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.

runTransaction(updateFunction: (transaction: Transaction) => Promise): Promise<any>;

settings

</>

Specifies custom settings to be used to configure the Firestore instance. Must be set before invoking any other methods.

settings(settings: Settings): Promise<void>;

terminate

</>

Typically called to ensure a new Firestore instance is initialized before calling firebase.firestore().clearPersistence().

terminate(): Promise<void>;

waitForPendingWrites

</>

Waits until all currently pending writes for the active user have been acknowledged by the backend.

waitForPendingWrites(): Promise<void>;

Statics

Blob

</>

Returns the Blob class.

firestore.Blob: Blob;

CACHE_SIZE_UNLIMITED

</>

Used to set the cache size to unlimited when passing to cacheSizeBytes in firebase.firestore().settings().

firestore.CACHE_SIZE_UNLIMITED: number;

FieldPath

</>

Returns the FieldPath class.

firestore.FieldPath: FieldPath;

FieldValue

</>

Returns the FieldValue class.

firestore.FieldValue: FieldValue;

GeoPoint

</>

Returns the GeoPoint class.

firestore.GeoPoint: GeoPoint;

Timestamp

</>

Returns the Timestamp class.

firestore.Timestamp: Timestamp;

setLogLevel

</>

Sets the verbosity of Cloud Firestore native device logs (debug, error, or silent).

firestore.setLogLevel(logLevel: "debug" | "error" | "silent"): void;