message  Send Feedback

firestore

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

Methods


Properties

app

app: FirebaseApp;
keyboard_return Inherited from 
FirebaseModule.app

The current FirebaseApp instance for this Firebase service.


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.

Example

const batch = firebase.firestore().batch();
batch.delete(...);

collection

collection(
  collectionPath: string
): CollectionReference;

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

Example

const collectionReference = firebase.firestore().collection('users');

Parameters

  • collectionPath: string
    A slash-separated path to a collection.

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.

Example

const collectionGroup = firebase.firestore().collectionGroup('orders');

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.

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 a promise that is resolved once the network has been disabled.

Example

await firebase.firestore().disableNetwork();

doc

doc(
  documentPath: string
): DocumentReference;

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

Example

const documentReference = firebase.firestore().doc('users/alovelace');

Parameters

  • documentPath: string
    A slash-separated path to a document.

enableNetwork

enableNetwork(): Promise<void>;

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

Example

await firebase.firestore().enableNetwork();

runTransaction

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

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.

Example

const cityRef = firebase.firestore().doc('cities/SF');
await firebase.firestore()
.runTransaction(async (transaction) => {
const snapshot = await transaction.get(cityRef);
await transaction.update(cityRef, {
population: snapshot.data().population + 1,
});
});

Parameters


settings

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

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

Example

const settings = {
cacheSizeBytes: firebase.firestore.CACHE_SIZE_UNLIMITED,
};
await firebase.firestore().settings(settings);

Parameters


React Native Market

Looking for pre-built React Native apps to kick start your next project? Check out the React Native Market by Invertase.

Your purchases help support our open-source projects such as React Native Firebase. All items are currently 50% off to celebrate the release of React Native Firebase version 6.
shopping_cartVisit React Native Market