---
title: Capacitor Firestore Plugin for Android, iOS & Web
description: Unofficial Capacitor plugin for Firebase Cloud Firestore SDK to store and sync data in real-time with support for Android, iOS, and Web.
tags:
  - Android
  - iOS
  - Web
search:
  boost: 2
faq: true
github_repo: capawesome-team/capacitor-firebase
npm_package: "@capacitor-firebase/firestore"
sponsor:
  name: AppScreens
  image: /docs/assets/images/sponsors/appscreens-logo.png
  url: https://appscreens.com/?_locale=en&utm_source=capawesome&utm_medium=referral&utm_campaign=capawesome&gclid=capawesome
---

# Capacitor Firebase Cloud Firestore Plugin

Unofficial Capacitor plugin for [Firebase Cloud Firestore](https://firebase.google.com/docs/firestore/).[^1]

<div class="capawesome-z29o10a">
  <a href="https://capawesome.io/" target="_blank">
    <img alt="Ship a fix in one command with Capawesome Cloud Live Updates, no store review" src="https://capawesome.io/assets/banners/cloud-ship-a-fix-in-one-command.png" />
  </a>
</div>

## Use Cases

The Cloud Firestore plugin is typically used to store and sync app data in the cloud, for example:

- **Real-time updates**: Keep your UI up to date by listening to document and collection changes with snapshot listeners.
- **User-generated content**: Create, read, update, and delete documents for user profiles, posts, or other app data.
- **Complex queries**: Filter and sort collections with composite filters and query constraints such as `where`, `orderBy`, and `limit`.
- **Offline support**: Enable offline persistence and control network access to work with locally cached data.
- **Atomic writes**: Perform multiple write operations as a single atomic batch with `writeBatch(...)`.
- **Multiple Firebase projects**: Read and write data of another Firebase project with the `appName` option.

## Compatibility

| Plugin Version | Capacitor Version | Status         |
| -------------- | ----------------- | -------------- |
| 9.x.x          | >=9.x.x           | Active support |
| 8.x.x          | 8.x.x             | Deprecated     |
| 7.x.x          | 7.x.x             | Deprecated     |
| 6.x.x          | 6.x.x             | Deprecated     |

## Guides

- [Announcing the Capacitor Firebase Cloud Firestore Plugin](https://capawesome.io/blog/announcing-the-capacitor-firebase-cloud-firestore-plugin/)
- [Capacitor Firestore: Real-Time Data & Offline Sync](https://capawesome.io/blog/capacitor-firebase-cloud-firestore-guide/): Real-time listeners, offline persistence, and atomic writes with this plugin.
- [How to Wrap an Angular App with Capacitor and Firebase](https://capawesome.io/blog/how-to-wrap-an-angular-app-with-capacitor-and-firebase/): Uses this plugin alongside Cloud Storage to store and sync user data.
- [How to Use Firebase in a Capacitor App](https://capawesome.io/blog/how-to-use-firebase-in-a-capacitor-app/): How the database combines with Authentication, Storage, and the rest of the family in a real app.

## Installation

You can use our **AI-Assisted Setup** to install the plugin.
Add the [Capawesome Skills](https://github.com/capawesome-team/skills) to your AI tool using the following command:

```bash
npx skills add capawesome-team/skills --skill capacitor-plugins
```

Then use the following prompt:

```
Use the `capacitor-plugins` skill from `capawesome-team/skills` to install the `@capacitor-firebase/firestore` plugin in my project.
```

If you prefer **Manual Setup**, install the plugin by running the following commands and follow the platform-specific instructions below:

```bash
npm install @capacitor-firebase/firestore firebase
npx cap sync
```

The plugin only needs the `firebase` package on the Web. If your app only runs on Android and iOS, you can [install the plugin without it](https://github.com/capawesome-team/capacitor-firebase/blob/main/docs/firebase-js-sdk.md#apps-that-only-run-on-android-and-ios).

Add Firebase to your project if you haven't already ([Android](https://github.com/capawesome-team/capacitor-firebase/blob/main/docs/firebase-setup.md#android) / [iOS](https://github.com/capawesome-team/capacitor-firebase/blob/main/docs/firebase-setup.md#ios) / [Web](https://github.com/capawesome-team/capacitor-firebase/blob/main/docs/firebase-setup.md#web)).

### Android

#### Variables

If needed, you can define the following project variable in your app’s `variables.gradle` file to change the default version of the dependency:

- `$firebaseFirestoreVersion` version of `com.google.firebase:firebase-firestore` (default: `27.2.0`)

This can be useful if you encounter dependency conflicts with other plugins in your project.

### iOS

This plugin supports [Swift Package Manager](https://capacitorjs.com/docs/ios/spm) only. CocoaPods is not supported.

#### Swift Package Manager

Add the following to your `capacitor.config.json` (or `capacitor.config.ts`) to avoid a [SwiftPM package identity collision](https://github.com/capawesome-team/capacitor-firebase/issues/959):

```json
{
  "experimental": {
    "ios": {
      "spm": {
        "packageOptions": {
          "@capacitor-firebase/firestore": {
            "symlink": true
          }
        }
      }
    }
  }
}
```

**Attention**: SPM `packageOptions` support requires Capacitor CLI **8.4.0+**.

## Configuration

<docgen-config>
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->

These configuration values are available:

| Prop             | Type                | Description                                                                                                                                                                                                    | Since |
| ---------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
| **`databaseId`** | <code>string</code> | The database ID of the Firestore database to use. This option applies only to calls without `appName`. A call with `appName` always uses the default database of that app. Only available for Android and iOS. | 8.2.0 |

### Examples

In `capacitor.config.json`:

```json
{
  "plugins": {
    "FirebaseFirestore": {
      "databaseId": undefined
    }
  }
}
```

In `capacitor.config.ts`:

```ts
/// <reference types="@capacitor-firebase/firestore" />

import { CapacitorConfig } from '@capacitor/cli';

const config: CapacitorConfig = {
  plugins: {
    FirebaseFirestore: {
      databaseId: undefined,
    },
  },
};

export default config;
```

</docgen-config>

## Demo

A working example can be found here: [robingenz/capacitor-firebase-plugin-demo](https://github.com/robingenz/capacitor-firebase-plugin-demo)

## Starter templates

The following starter templates are available:

- [Ionstarter Angular Firebase](https://ionstarter.dev/)

## Usage

The following examples show how to create, read, update, and delete documents, update documents with field values, perform batched writes, query collections, control network access, use the Firebase Emulator, and listen for and remove real-time updates.

### Create a document

Add a new document to a collection with an auto-generated ID, or write a document at a known reference with `setDocument(...)`. Set `merge` to `true` to merge the data with an existing document:

```typescript
import { FirebaseFirestore } from '@capacitor-firebase/firestore';

const addDocument = async () => {
  await FirebaseFirestore.addDocument({
    reference: 'users',
    data: { 
      first: 'Alan', 
      last: 'Turing', 
      born: 1912 
    },
  });
};

const setDocument = async () => {
  await FirebaseFirestore.setDocument({
    reference: 'users/Aorq09lkt1ynbR7xhTUx',
    data: { 
      first: 'Alan', 
      last: 'Turing', 
      born: 1912 
    },
    merge: true,
  });
};
```

### Read a document

Read a single document by its reference:

```typescript
import { FirebaseFirestore } from '@capacitor-firebase/firestore';

const getDocument = async () => {
  const { snapshot } = await FirebaseFirestore.getDocument({
    reference: 'users/Aorq09lkt1ynbR7xhTUx',
  });
  return snapshot;
};
```

### Update or delete a document

Update fields of an existing document or delete it entirely:

```typescript
import { FirebaseFirestore } from '@capacitor-firebase/firestore';

const updateDocument = async () => {
  await FirebaseFirestore.updateDocument({
    reference: 'users/Aorq09lkt1ynbR7xhTUx',
    data: { 
      first: 'Alan', 
      last: 'Turing', 
      born: 1912 
    },
  });
};

const deleteDocument = async () => {
  await FirebaseFirestore.deleteDocument({
    reference: 'users/Aorq09lkt1ynbR7xhTUx',
  });
};
```

### Update a document with field values

Use `FieldValue` helpers to increment numbers, set server timestamps, modify arrays, or delete fields:

```typescript
import { FieldValue, FirebaseFirestore } from '@capacitor-firebase/firestore';

const updateDocumentWithFieldValue = async () => {
  await FirebaseFirestore.updateDocument({
    reference: 'users/Aorq09lkt1ynbR7xhTUx',
    data: {
      born: FieldValue.increment(1),
      updatedAt: FieldValue.serverTimestamp(),
      nicknames: FieldValue.arrayUnion('Prof'),
      tags: FieldValue.arrayRemove('draft'),
      deprecatedField: FieldValue.delete(),
    },
  });
};
```

### Perform a batched write

Execute multiple set, update, and delete operations as a single atomic batch:

```typescript
import { FirebaseFirestore } from '@capacitor-firebase/firestore';

const writeBatch = async () => {
  await FirebaseFirestore.writeBatch({
    operations: [
      {
        type: 'set',
        reference: 'users/Aorq09lkt1ynbR7xhTUx',
        data: { 
          first: 'Alan', 
          last: 'Turing', 
          born: 1912 
        },
        options: { merge: true },
      },
      {
        type: 'update',
        reference: 'users/Aorq09lkt1ynbR7xhTUx',
        data: { 
          first: 'Alan', 
          last: 'Turing', 
          born: 1912 
        },
      },
      {
        type: 'delete',
        reference: 'users/Aorq09lkt1ynbR7xhTUx',
      },
    ],
  });
};
```

### Query a collection

Read multiple documents from a collection or a collection group. You can filter the results with a composite filter and apply query constraints such as `orderBy` and `limit`:

```typescript
import { FirebaseFirestore } from '@capacitor-firebase/firestore';

const getCollection = async () => {
  const { snapshots } = await FirebaseFirestore.getCollection({
    reference: 'users',
    compositeFilter: {
      type: 'and',
      queryConstraints: [
        {
          type: 'where',
          fieldPath: 'born',
          opStr: '==',
          value: 1912,
        },
      ],
    },
    queryConstraints: [
      {
        type: 'orderBy',
        fieldPath: 'born',
        directionStr: 'desc',
      },
      {
        type: 'limit',
        limit: 10,
      },
    ],
  });
  return snapshots;
};

const getCollectionGroup = async () => {
  const { snapshots } = await FirebaseFirestore.getCollectionGroup({
    reference: 'users',
    compositeFilter: {
      type: 'and',
      queryConstraints: [
        {
          type: 'where',
          fieldPath: 'born',
          opStr: '==',
          value: 1912,
        },
      ],
    },
    queryConstraints: [
      {
        type: 'orderBy',
        fieldPath: 'born',
        directionStr: 'desc',
      },
      {
        type: 'limit',
        limit: 10,
      },
    ],
  });
  return snapshots;
};
```

### Control network access

Disable and re-enable the use of the network, for example to force the plugin to work with locally cached data:

```typescript
import { FirebaseFirestore } from '@capacitor-firebase/firestore';

const enableNetwork = async () => {
  await FirebaseFirestore.enableNetwork();
};

const disableNetwork = async () => {
  await FirebaseFirestore.disableNetwork();
};
```

### Use the Firebase Emulator

Connect the plugin to a local [Firebase Emulator](https://firebase.google.com/docs/emulator-suite) instance during development:

```typescript
import { FirebaseFirestore } from '@capacitor-firebase/firestore';

const useEmulator = async () => {
  await FirebaseFirestore.useEmulator({
    host: '10.0.2.2',
    port: 9001,
  });
};
```

### Listen for real-time updates

Attach snapshot listeners to a document, a collection, or a collection group to get notified whenever the data changes:

```typescript
import { FirebaseFirestore } from '@capacitor-firebase/firestore';

const addDocumentSnapshotListener = async () => {
  const callbackId = await FirebaseFirestore.addDocumentSnapshotListener(
    {
      reference: 'users/Aorq09lkt1ynbR7xhTUx',
    },
    (event, error) => {
      if (error) {
        console.error(error);
      } else {
        console.log(event);
      }
    }
  );
  return callbackId;
};

const addCollectionSnapshotListener = async () => {
  const callbackId = await FirebaseFirestore.addCollectionSnapshotListener(
    {
      reference: 'users',
      compositeFilter: {
        type: 'and',
        queryConstraints: [
          {
            type: 'where',
            fieldPath: 'born',
            opStr: '==',
            value: 1912,
          },
        ],
      },
      queryConstraints: [
        {
          type: 'orderBy',
          fieldPath: 'born',
          directionStr: 'desc',
        },
        {
          type: 'limit',
          limit: 10,
        },
      ],
    },
    (event, error) => {
      if (error) {
        console.error(error);
      } else {
        console.log(event);
      }
    }
  );
  return callbackId;
};

const addCollectionGroupSnapshotListener = async () => {
  const callbackId = await FirebaseFirestore.addCollectionGroupSnapshotListener(
    {
      reference: 'users',
      compositeFilter: {
        type: 'and',
        queryConstraints: [
          {
            type: 'where',
            fieldPath: 'born',
            opStr: '==',
            value: 1912,
          },
        ],
      },
      queryConstraints: [
        {
          type: 'orderBy',
          fieldPath: 'born',
          directionStr: 'desc',
        },
        {
          type: 'limit',
          limit: 10,
        },
      ],
    },
    (event, error) => {
      if (error) {
        console.error(error);
      } else {
        console.log(event);
      }
    }
  );
  return callbackId;
};
```

### Remove listeners

Remove a single snapshot listener by its callback ID or remove all listeners at once:

```typescript
import { FirebaseFirestore } from '@capacitor-firebase/firestore';

const removeSnapshotListener = async (callbackId: string) => {
  await FirebaseFirestore.removeSnapshotListener({
    callbackId,
  });
};

const removeAllListeners = async () => {
  await FirebaseFirestore.removeAllListeners();
};
```

### Use another Firebase project

Pass the `appName` option to use a Firebase app other than the default app, for example to read data of a second Firebase project. Initialize the app with the `initializeApp(...)` method of the [Firebase App](https://capawesome.io/docs/sdks/capacitor/firebase/app/) plugin first. Then pass its name as `appName`:

```typescript
import { FirebaseFirestore } from '@capacitor-firebase/firestore';

const getDocument = async () => {
  const { snapshot } = await FirebaseFirestore.getDocument({
    reference: 'users/Aorq09lkt1ynbR7xhTUx',
    appName: 'secondary',
  });
  return snapshot;
};
```

Every app has its own Firestore instance. Methods that change the instance, such as `useEmulator(...)`, `enablePersistence(...)`, `disablePersistence(...)` and `disableNetwork(...)`, apply only to the app of that call. Call them once for every `appName` that needs them.

To use the default app, leave `appName` out.

**Attention**: A call with `appName` is made as the user of that app. To sign in a user to it, pass the same `appName` to the methods of the [Firebase Authentication](https://capawesome.io/docs/sdks/capacitor/firebase/authentication/) plugin.

## API

<docgen-index>

* [`addDocument(...)`](#adddocument)
* [`addCollectionGroupSnapshotListener(...)`](#addcollectiongroupsnapshotlistener)
* [`addCollectionSnapshotListener(...)`](#addcollectionsnapshotlistener)
* [`addDocumentSnapshotListener(...)`](#adddocumentsnapshotlistener)
* [`clearPersistence(...)`](#clearpersistence)
* [`deleteDocument(...)`](#deletedocument)
* [`disableNetwork(...)`](#disablenetwork)
* [`disablePersistence(...)`](#disablepersistence)
* [`enablePersistence(...)`](#enablepersistence)
* [`enableNetwork(...)`](#enablenetwork)
* [`getCollection(...)`](#getcollection)
* [`getCollectionGroup(...)`](#getcollectiongroup)
* [`getCountFromServer(...)`](#getcountfromserver)
* [`getDocument(...)`](#getdocument)
* [`removeAllListeners()`](#removealllisteners)
* [`removeSnapshotListener(...)`](#removesnapshotlistener)
* [`setDocument(...)`](#setdocument)
* [`terminate(...)`](#terminate)
* [`updateDocument(...)`](#updatedocument)
* [`useEmulator(...)`](#useemulator)
* [`writeBatch(...)`](#writebatch)
* [Interfaces](#interfaces)
* [Type Aliases](#type-aliases)

</docgen-index>

<docgen-api>
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->

### addDocument(...)

```typescript
addDocument(options: AddDocumentOptions) => Promise<AddDocumentResult>
```

Adds a new document to a collection with the given data.

| Param         | Type                                                              |
| ------------- | ----------------------------------------------------------------- |
| **`options`** | <code><a href="#adddocumentoptions">AddDocumentOptions</a></code> |

**Returns:** <code>Promise&lt;<a href="#adddocumentresult">AddDocumentResult</a>&gt;</code>

**Since:** 5.2.0

--------------------


### addCollectionGroupSnapshotListener(...)

```typescript
addCollectionGroupSnapshotListener<T extends DocumentData = DocumentData>(options: AddCollectionGroupSnapshotListenerOptions, callback: AddCollectionGroupSnapshotListenerCallback<T>) => Promise<CallbackId>
```

Adds a listener for collection group snapshot events.

| Param          | Type                                                                                                                       |
| -------------- | -------------------------------------------------------------------------------------------------------------------------- |
| **`options`**  | <code><a href="#addcollectiongroupsnapshotlisteneroptions">AddCollectionGroupSnapshotListenerOptions</a></code>            |
| **`callback`** | <code><a href="#addcollectiongroupsnapshotlistenercallback">AddCollectionGroupSnapshotListenerCallback</a>&lt;T&gt;</code> |

**Returns:** <code>Promise&lt;string&gt;</code>

**Since:** 6.1.0

--------------------


### addCollectionSnapshotListener(...)

```typescript
addCollectionSnapshotListener<T extends DocumentData = DocumentData>(options: AddCollectionSnapshotListenerOptions, callback: AddCollectionSnapshotListenerCallback<T>) => Promise<CallbackId>
```

Adds a listener for collection snapshot events.

| Param          | Type                                                                                                             |
| -------------- | ---------------------------------------------------------------------------------------------------------------- |
| **`options`**  | <code><a href="#addcollectionsnapshotlisteneroptions">AddCollectionSnapshotListenerOptions</a></code>            |
| **`callback`** | <code><a href="#addcollectionsnapshotlistenercallback">AddCollectionSnapshotListenerCallback</a>&lt;T&gt;</code> |

**Returns:** <code>Promise&lt;string&gt;</code>

**Since:** 5.2.0

--------------------


### addDocumentSnapshotListener(...)

```typescript
addDocumentSnapshotListener<T extends DocumentData = DocumentData>(options: AddDocumentSnapshotListenerOptions, callback: AddDocumentSnapshotListenerCallback<T>) => Promise<CallbackId>
```

Adds a listener for document snapshot events.

| Param          | Type                                                                                                         |
| -------------- | ------------------------------------------------------------------------------------------------------------ |
| **`options`**  | <code><a href="#adddocumentsnapshotlisteneroptions">AddDocumentSnapshotListenerOptions</a></code>            |
| **`callback`** | <code><a href="#adddocumentsnapshotlistenercallback">AddDocumentSnapshotListenerCallback</a>&lt;T&gt;</code> |

**Returns:** <code>Promise&lt;string&gt;</code>

**Since:** 5.2.0

--------------------


### clearPersistence(...)

```typescript
clearPersistence(options?: ClearPersistenceOptions | undefined) => Promise<void>
```

Clears the persistent storage. This includes pending writes and cached documents.

**Attention**: The Firestore instance must not be running.
Call this method before the first read or write, or after `terminate()`.

| Param         | Type                                                                        |
| ------------- | --------------------------------------------------------------------------- |
| **`options`** | <code><a href="#clearpersistenceoptions">ClearPersistenceOptions</a></code> |

**Since:** 5.2.0

--------------------


### deleteDocument(...)

```typescript
deleteDocument(options: DeleteDocumentOptions) => Promise<void>
```

Deletes the document referred to by the specified reference.

| Param         | Type                                                                    |
| ------------- | ----------------------------------------------------------------------- |
| **`options`** | <code><a href="#deletedocumentoptions">DeleteDocumentOptions</a></code> |

**Since:** 5.2.0

--------------------


### disableNetwork(...)

```typescript
disableNetwork(options?: DisableNetworkOptions | undefined) => Promise<void>
```

Disables use of the network.

| Param         | Type                                                                    |
| ------------- | ----------------------------------------------------------------------- |
| **`options`** | <code><a href="#disablenetworkoptions">DisableNetworkOptions</a></code> |

**Since:** 5.2.0

--------------------


### disablePersistence(...)

```typescript
disablePersistence(options?: DisablePersistenceOptions | undefined) => Promise<void>
```

Disables offline persistence.

**Attention**: Must be called before any other Firestore method.

| Param         | Type                                                                            |
| ------------- | ------------------------------------------------------------------------------- |
| **`options`** | <code><a href="#disablepersistenceoptions">DisablePersistenceOptions</a></code> |

**Since:** 8.2.0

--------------------


### enablePersistence(...)

```typescript
enablePersistence(options?: EnablePersistenceOptions | undefined) => Promise<void>
```

Enables offline persistence.

**Attention**: Must be called before any other Firestore method.

| Param         | Type                                                                          |
| ------------- | ----------------------------------------------------------------------------- |
| **`options`** | <code><a href="#enablepersistenceoptions">EnablePersistenceOptions</a></code> |

**Since:** 8.2.0

--------------------


### enableNetwork(...)

```typescript
enableNetwork(options?: EnableNetworkOptions | undefined) => Promise<void>
```

Re-enables use of the network.

| Param         | Type                                                                  |
| ------------- | --------------------------------------------------------------------- |
| **`options`** | <code><a href="#enablenetworkoptions">EnableNetworkOptions</a></code> |

**Since:** 5.2.0

--------------------


### getCollection(...)

```typescript
getCollection<T extends DocumentData = DocumentData>(options: GetCollectionOptions) => Promise<GetCollectionResult<T>>
```

Reads the collection referenced by the specified reference.

| Param         | Type                                                                  |
| ------------- | --------------------------------------------------------------------- |
| **`options`** | <code><a href="#getcollectionoptions">GetCollectionOptions</a></code> |

**Returns:** <code>Promise&lt;<a href="#getcollectionresult">GetCollectionResult</a>&lt;T&gt;&gt;</code>

**Since:** 5.2.0

--------------------


### getCollectionGroup(...)

```typescript
getCollectionGroup<T extends DocumentData = DocumentData>(options: GetCollectionGroupOptions) => Promise<GetCollectionGroupResult<T>>
```

Reads the collection group referenced by the specified reference.

| Param         | Type                                                                            |
| ------------- | ------------------------------------------------------------------------------- |
| **`options`** | <code><a href="#getcollectiongroupoptions">GetCollectionGroupOptions</a></code> |

**Returns:** <code>Promise&lt;<a href="#getcollectiongroupresult">GetCollectionGroupResult</a>&lt;T&gt;&gt;</code>

--------------------


### getCountFromServer(...)

```typescript
getCountFromServer(options: GetCountFromServerOptions) => Promise<GetCountFromServerResult>
```

Fetches the number of documents in a collection.

| Param         | Type                                                                            |
| ------------- | ------------------------------------------------------------------------------- |
| **`options`** | <code><a href="#getcountfromserveroptions">GetCountFromServerOptions</a></code> |

**Returns:** <code>Promise&lt;<a href="#getcountfromserverresult">GetCountFromServerResult</a>&gt;</code>

**Since:** 6.4.0

--------------------


### getDocument(...)

```typescript
getDocument<T extends DocumentData = DocumentData>(options: GetDocumentOptions) => Promise<GetDocumentResult<T>>
```

Reads the document referred to by the specified reference.

| Param         | Type                                                              |
| ------------- | ----------------------------------------------------------------- |
| **`options`** | <code><a href="#getdocumentoptions">GetDocumentOptions</a></code> |

**Returns:** <code>Promise&lt;<a href="#getdocumentresult">GetDocumentResult</a>&lt;T&gt;&gt;</code>

**Since:** 5.2.0

--------------------


### removeAllListeners()

```typescript
removeAllListeners() => Promise<void>
```

Remove all listeners for this plugin.

**Since:** 5.2.0

--------------------


### removeSnapshotListener(...)

```typescript
removeSnapshotListener(options: RemoveSnapshotListenerOptions) => Promise<void>
```

Remove a listener for document or collection snapshot events.

| Param         | Type                                                                                    |
| ------------- | --------------------------------------------------------------------------------------- |
| **`options`** | <code><a href="#removesnapshotlisteneroptions">RemoveSnapshotListenerOptions</a></code> |

**Since:** 5.2.0

--------------------


### setDocument(...)

```typescript
setDocument(options: SetDocumentOptions) => Promise<void>
```

Writes to the document referred to by the specified reference.
If the document does not yet exist, it will be created.

| Param         | Type                                                              |
| ------------- | ----------------------------------------------------------------- |
| **`options`** | <code><a href="#setdocumentoptions">SetDocumentOptions</a></code> |

**Since:** 5.2.0

--------------------


### terminate(...)

```typescript
terminate(options?: TerminateOptions | undefined) => Promise<void>
```

Terminates the Firestore instance. The next call to any other method starts a new instance.

To clear the persistent storage while the app is running, call `terminate()`,
then `enablePersistence(...)` if the app uses it, then `clearPersistence()`.

**Attention**: Snapshot listeners stop receiving updates and must be removed.
On Web, each listener is called one last time with an error.
Calls that are still running may fail or never resolve.
The new instance starts with the default settings. An app that uses `enablePersistence(...)`,
`disablePersistence()` or `useEmulator(...)` must call it again.

| Param         | Type                                                          |
| ------------- | ------------------------------------------------------------- |
| **`options`** | <code><a href="#terminateoptions">TerminateOptions</a></code> |

**Since:** 8.7.0

--------------------


### updateDocument(...)

```typescript
updateDocument(options: UpdateDocumentOptions) => Promise<void>
```

Updates fields in the document referred to by the specified reference.

| Param         | Type                                                                    |
| ------------- | ----------------------------------------------------------------------- |
| **`options`** | <code><a href="#updatedocumentoptions">UpdateDocumentOptions</a></code> |

**Since:** 5.2.0

--------------------


### useEmulator(...)

```typescript
useEmulator(options: UseEmulatorOptions) => Promise<void>
```

Instrument your app to talk to the Firestore emulator.

| Param         | Type                                                              |
| ------------- | ----------------------------------------------------------------- |
| **`options`** | <code><a href="#useemulatoroptions">UseEmulatorOptions</a></code> |

**Since:** 6.1.0

--------------------


### writeBatch(...)

```typescript
writeBatch(options: WriteBatchOptions) => Promise<void>
```

Execute multiple write operations as a single batch.

| Param         | Type                                                            |
| ------------- | --------------------------------------------------------------- |
| **`options`** | <code><a href="#writebatchoptions">WriteBatchOptions</a></code> |

**Since:** 6.1.0

--------------------


### Interfaces


#### AddDocumentResult

| Prop            | Type                           | Description                                | Since |
| --------------- | ------------------------------ | ------------------------------------------ | ----- |
| **`reference`** | <code>DocumentReference</code> | The reference of the newly added document. | 5.2.0 |


#### AddDocumentOptions

| Prop            | Type                                                  | Description                                                                                                                                                         | Since |
| --------------- | ----------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
| **`reference`** | <code>string</code>                                   | The reference as a string, with path components separated by a forward slash (`/`).                                                                                 | 5.2.0 |
| **`data`**      | <code><a href="#documentdata">DocumentData</a></code> | An object containing the data for the new document.                                                                                                                 | 5.2.0 |
| **`appName`**   | <code>string</code>                                   | The name of the Firebase app to use. Initialize the app with the `initializeApp(...)` method of the Firebase App plugin first. If not set, the default app is used. | 8.7.0 |


#### DocumentData


#### AddCollectionGroupSnapshotListenerOptions

| Prop                   | Type                                                                                      | Description                                                                                                                                                         | Since |
| ---------------------- | ----------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
| **`reference`**        | <code>string</code>                                                                       | The reference as a string, with path components separated by a forward slash (`/`).                                                                                 | 6.1.0 |
| **`compositeFilter`**  | <code><a href="#querycompositefilterconstraint">QueryCompositeFilterConstraint</a></code> | The filter to apply.                                                                                                                                                | 6.1.0 |
| **`queryConstraints`** | <code>QueryNonFilterConstraint[]</code>                                                   | Narrow or order the set of documents to retrieve, but do not explicitly filter for document fields.                                                                 | 6.1.0 |
| **`appName`**          | <code>string</code>                                                                       | The name of the Firebase app to use. Initialize the app with the `initializeApp(...)` method of the Firebase App plugin first. If not set, the default app is used. | 8.7.0 |


#### QueryCompositeFilterConstraint

| Prop                   | Type                                 | Description                 | Since |
| ---------------------- | ------------------------------------ | --------------------------- | ----- |
| **`type`**             | <code>'and' \| 'or'</code>           | The type of the constraint. | 5.2.0 |
| **`queryConstraints`** | <code>QueryFilterConstraint[]</code> | The filters to apply.       | 5.2.0 |


#### QueryFieldFilterConstraint

| Prop            | Type                                                    | Description                    | Since |
| --------------- | ------------------------------------------------------- | ------------------------------ | ----- |
| **`type`**      | <code>'where'</code>                                    | The type of the constraint.    | 5.2.0 |
| **`fieldPath`** | <code>string</code>                                     | The path to compare.           | 5.2.0 |
| **`opStr`**     | <code><a href="#queryoperator">QueryOperator</a></code> | The operation string to apply. | 5.2.0 |
| **`value`**     | <code>any</code>                                        | The value for comparison.      | 5.2.0 |


#### QueryOrderByConstraint

| Prop               | Type                                                          | Description                 | Since |
| ------------------ | ------------------------------------------------------------- | --------------------------- | ----- |
| **`type`**         | <code>'orderBy'</code>                                        | The type of the constraint. | 5.2.0 |
| **`fieldPath`**    | <code>string</code>                                           | The path to compare.        | 5.2.0 |
| **`directionStr`** | <code><a href="#orderbydirection">OrderByDirection</a></code> | The direction to sort by.   | 5.2.0 |


#### QueryLimitConstraint

| Prop        | Type                                  | Description                            | Since |
| ----------- | ------------------------------------- | -------------------------------------- | ----- |
| **`type`**  | <code>'limit' \| 'limitToLast'</code> | The type of the constraint.            | 5.2.0 |
| **`limit`** | <code>number</code>                   | The maximum number of items to return. | 5.2.0 |


#### QueryStartAtConstraint

| Prop            | Type                                   | Description                                                                                                                                                        | Since |
| --------------- | -------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----- |
| **`type`**      | <code>'startAt' \| 'startAfter'</code> | The type of the constraint.                                                                                                                                        | 5.2.0 |
| **`reference`** | <code>string</code>                    | The reference to start at or after as a string, with path components separated by a forward slash (`/`). **Attention**: This requires an additional document read. | 5.2.0 |


#### QueryEndAtConstraint

| Prop            | Type                                | Description                                                                                                                                                          | Since |
| --------------- | ----------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
| **`type`**      | <code>'endAt' \| 'endBefore'</code> | The type of the constraint.                                                                                                                                          | 5.2.0 |
| **`reference`** | <code>string</code>                 | The reference as to end at or before as a string, with path components separated by a forward slash (`/`). **Attention**: This requires an additional document read. | 5.2.0 |


#### GetCollectionGroupResult

| Prop            | Type                                                                     | Description                      | Since |
| --------------- | ------------------------------------------------------------------------ | -------------------------------- | ----- |
| **`snapshots`** | <code><a href="#documentsnapshot">DocumentSnapshot</a>&lt;T&gt;[]</code> | The documents in the collection. | 5.2.0 |


#### DocumentSnapshot

| Prop           | Type                                                          | Description                                                                                   | Since |
| -------------- | ------------------------------------------------------------- | --------------------------------------------------------------------------------------------- | ----- |
| **`id`**       | <code>string</code>                                           | The document's identifier within its collection.                                              | 5.2.0 |
| **`path`**     | <code>string</code>                                           | The path of the document.                                                                     | 5.2.0 |
| **`data`**     | <code>T \| null</code>                                        | An object containing the data for the document. Returns `null` if the document doesn't exist. | 5.2.0 |
| **`metadata`** | <code><a href="#snapshotmetadata">SnapshotMetadata</a></code> | Metadata about the snapshot, concerning its source and if it has local modifications.         | 6.2.0 |


#### SnapshotMetadata

| Prop                   | Type                 | Description                                               | Since |
| ---------------------- | -------------------- | --------------------------------------------------------- | ----- |
| **`fromCache`**        | <code>boolean</code> | True if the snapshot was created from cached data.        | 6.2.0 |
| **`hasPendingWrites`** | <code>boolean</code> | True if the snapshot was created from pending write data. | 6.2.0 |


#### AddCollectionSnapshotListenerOptions

| Prop                   | Type                                                                                      | Description                                                                                                                                                         | Since |
| ---------------------- | ----------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
| **`reference`**        | <code>string</code>                                                                       | The reference as a string, with path components separated by a forward slash (`/`).                                                                                 | 5.2.0 |
| **`compositeFilter`**  | <code><a href="#querycompositefilterconstraint">QueryCompositeFilterConstraint</a></code> | The filter to apply.                                                                                                                                                | 5.2.0 |
| **`queryConstraints`** | <code>QueryNonFilterConstraint[]</code>                                                   | Narrow or order the set of documents to retrieve, but do not explicitly filter for document fields.                                                                 | 5.2.0 |
| **`appName`**          | <code>string</code>                                                                       | The name of the Firebase app to use. Initialize the app with the `initializeApp(...)` method of the Firebase App plugin first. If not set, the default app is used. | 8.7.0 |


#### GetCollectionResult

| Prop            | Type                                                                     | Description                      | Since |
| --------------- | ------------------------------------------------------------------------ | -------------------------------- | ----- |
| **`snapshots`** | <code><a href="#documentsnapshot">DocumentSnapshot</a>&lt;T&gt;[]</code> | The documents in the collection. | 5.2.0 |


#### AddDocumentSnapshotListenerOptions

| Prop            | Type                | Description                                                                                                                                                         | Since |
| --------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
| **`reference`** | <code>string</code> | The reference as a string, with path components separated by a forward slash (`/`).                                                                                 | 5.2.0 |
| **`appName`**   | <code>string</code> | The name of the Firebase app to use. Initialize the app with the `initializeApp(...)` method of the Firebase App plugin first. If not set, the default app is used. | 8.7.0 |


#### GetDocumentResult

| Prop           | Type                                                                   | Description                    | Since |
| -------------- | ---------------------------------------------------------------------- | ------------------------------ | ----- |
| **`snapshot`** | <code><a href="#documentsnapshot">DocumentSnapshot</a>&lt;T&gt;</code> | The current document contents. | 5.2.0 |


#### ClearPersistenceOptions

| Prop          | Type                | Description                                                                                                                                                         | Since |
| ------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
| **`appName`** | <code>string</code> | The name of the Firebase app to use. Initialize the app with the `initializeApp(...)` method of the Firebase App plugin first. If not set, the default app is used. | 8.7.0 |


#### DeleteDocumentOptions

| Prop            | Type                | Description                                                                                                                                                         | Since |
| --------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
| **`reference`** | <code>string</code> | The reference as a string, with path components separated by a forward slash (`/`).                                                                                 | 5.2.0 |
| **`appName`**   | <code>string</code> | The name of the Firebase app to use. Initialize the app with the `initializeApp(...)` method of the Firebase App plugin first. If not set, the default app is used. | 8.7.0 |


#### DisableNetworkOptions

| Prop          | Type                | Description                                                                                                                                                         | Since |
| ------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
| **`appName`** | <code>string</code> | The name of the Firebase app to use. Initialize the app with the `initializeApp(...)` method of the Firebase App plugin first. If not set, the default app is used. | 8.7.0 |


#### DisablePersistenceOptions

| Prop          | Type                | Description                                                                                                                                                         | Since |
| ------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
| **`appName`** | <code>string</code> | The name of the Firebase app to use. Initialize the app with the `initializeApp(...)` method of the Firebase App plugin first. If not set, the default app is used. | 8.7.0 |


#### EnablePersistenceOptions

| Prop                  | Type                 | Description                                                                                                                                                         | Default                         | Since |
| --------------------- | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------- | ----- |
| **`cacheSizeBytes`**  | <code>number</code>  | The cache size in bytes.                                                                                                                                            | <code>104857600 (100 MB)</code> | 8.2.0 |
| **`synchronizeTabs`** | <code>boolean</code> | Whether to synchronize persistence across multiple tabs. Only available for Web.                                                                                    | <code>false</code>              | 8.2.0 |
| **`appName`**         | <code>string</code>  | The name of the Firebase app to use. Initialize the app with the `initializeApp(...)` method of the Firebase App plugin first. If not set, the default app is used. |                                 | 8.7.0 |


#### EnableNetworkOptions

| Prop          | Type                | Description                                                                                                                                                         | Since |
| ------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
| **`appName`** | <code>string</code> | The name of the Firebase app to use. Initialize the app with the `initializeApp(...)` method of the Firebase App plugin first. If not set, the default app is used. | 8.7.0 |


#### GetCollectionOptions

| Prop                   | Type                                                                                      | Description                                                                                                                                                         | Since |
| ---------------------- | ----------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
| **`reference`**        | <code>string</code>                                                                       | The reference as a string, with path components separated by a forward slash (`/`).                                                                                 | 5.2.0 |
| **`compositeFilter`**  | <code><a href="#querycompositefilterconstraint">QueryCompositeFilterConstraint</a></code> | The filter to apply.                                                                                                                                                | 5.2.0 |
| **`queryConstraints`** | <code>QueryNonFilterConstraint[]</code>                                                   | Narrow or order the set of documents to retrieve, but do not explicitly filter for document fields.                                                                 | 5.2.0 |
| **`appName`**          | <code>string</code>                                                                       | The name of the Firebase app to use. Initialize the app with the `initializeApp(...)` method of the Firebase App plugin first. If not set, the default app is used. | 8.7.0 |


#### GetCollectionGroupOptions

| Prop                   | Type                                                                                      | Description                                                                                                                                                         | Since |
| ---------------------- | ----------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
| **`reference`**        | <code>string</code>                                                                       | The reference as a string, with path components separated by a forward slash (`/`).                                                                                 | 5.2.0 |
| **`compositeFilter`**  | <code><a href="#querycompositefilterconstraint">QueryCompositeFilterConstraint</a></code> | The filter to apply.                                                                                                                                                | 5.2.0 |
| **`queryConstraints`** | <code>QueryNonFilterConstraint[]</code>                                                   | Narrow or order the set of documents to retrieve, but do not explicitly filter for document fields.                                                                 | 5.2.0 |
| **`appName`**          | <code>string</code>                                                                       | The name of the Firebase app to use. Initialize the app with the `initializeApp(...)` method of the Firebase App plugin first. If not set, the default app is used. | 8.7.0 |


#### GetCountFromServerResult

| Prop        | Type                | Description                                | Since |
| ----------- | ------------------- | ------------------------------------------ | ----- |
| **`count`** | <code>number</code> | The number of documents in the collection. | 6.4.0 |


#### GetCountFromServerOptions

| Prop                   | Type                                                                                      | Description                                                                                                                                                         | Since |
| ---------------------- | ----------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
| **`reference`**        | <code>string</code>                                                                       | The reference as a string, with path components separated by a forward slash (`/`).                                                                                 | 6.4.0 |
| **`compositeFilter`**  | <code><a href="#querycompositefilterconstraint">QueryCompositeFilterConstraint</a></code> | The filter to apply.                                                                                                                                                | 8.3.0 |
| **`queryConstraints`** | <code>QueryNonFilterConstraint[]</code>                                                   | Narrow or order the set of documents to count, but do not explicitly filter for document fields.                                                                    | 8.3.0 |
| **`appName`**          | <code>string</code>                                                                       | The name of the Firebase app to use. Initialize the app with the `initializeApp(...)` method of the Firebase App plugin first. If not set, the default app is used. | 8.7.0 |


#### GetDocumentOptions

| Prop            | Type                | Description                                                                                                                                                         | Since |
| --------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
| **`reference`** | <code>string</code> | The reference as a string, with path components separated by a forward slash (`/`).                                                                                 | 5.2.0 |
| **`appName`**   | <code>string</code> | The name of the Firebase app to use. Initialize the app with the `initializeApp(...)` method of the Firebase App plugin first. If not set, the default app is used. | 8.7.0 |


#### RemoveSnapshotListenerOptions

| Prop             | Type                                              | Since |
| ---------------- | ------------------------------------------------- | ----- |
| **`callbackId`** | <code><a href="#callbackid">CallbackId</a></code> | 5.2.0 |


#### SetDocumentOptions

| Prop            | Type                                                  | Description                                                                                                                                                         | Default            | Since |
| --------------- | ----------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ----- |
| **`reference`** | <code>string</code>                                   | The reference as a string, with path components separated by a forward slash (`/`).                                                                                 |                    | 5.2.0 |
| **`data`**      | <code><a href="#documentdata">DocumentData</a></code> | An object containing the data for the new document.                                                                                                                 |                    | 5.2.0 |
| **`merge`**     | <code>boolean</code>                                  | Whether to merge the provided data with an existing document.                                                                                                       | <code>false</code> | 5.2.0 |
| **`appName`**   | <code>string</code>                                   | The name of the Firebase app to use. Initialize the app with the `initializeApp(...)` method of the Firebase App plugin first. If not set, the default app is used. |                    | 8.7.0 |


#### TerminateOptions

| Prop          | Type                | Description                                                                                                                                                         | Since |
| ------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
| **`appName`** | <code>string</code> | The name of the Firebase app to use. Initialize the app with the `initializeApp(...)` method of the Firebase App plugin first. If not set, the default app is used. | 8.7.0 |


#### UpdateDocumentOptions

| Prop            | Type                                                  | Description                                                                                                                                                         | Since |
| --------------- | ----------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
| **`reference`** | <code>string</code>                                   | The reference as a string, with path components separated by a forward slash (`/`).                                                                                 | 5.2.0 |
| **`data`**      | <code><a href="#documentdata">DocumentData</a></code> | An object containing the data for the new document.                                                                                                                 | 5.2.0 |
| **`appName`**   | <code>string</code>                                   | The name of the Firebase app to use. Initialize the app with the `initializeApp(...)` method of the Firebase App plugin first. If not set, the default app is used. | 8.7.0 |


#### UseEmulatorOptions

| Prop          | Type                | Description                                                                                                                                                                     | Default           | Since |
| ------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------- | ----- |
| **`host`**    | <code>string</code> | The emulator host without any port or scheme. Note when using a Android Emulator device: 10.0.2.2 is the special IP address to connect to the 'localhost' of the host computer. |                   | 6.1.0 |
| **`port`**    | <code>number</code> | The emulator port.                                                                                                                                                              | <code>8080</code> | 6.1.0 |
| **`appName`** | <code>string</code> | The name of the Firebase app to use. Initialize the app with the `initializeApp(...)` method of the Firebase App plugin first. If not set, the default app is used.             |                   | 8.7.0 |


#### WriteBatchOptions

| Prop             | Type                               | Description                                                                                                                                                         | Since |
| ---------------- | ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
| **`operations`** | <code>WriteBatchOperation[]</code> | The operations to execute in the batch.                                                                                                                             | 6.1.0 |
| **`appName`**    | <code>string</code>                | The name of the Firebase app to use. Initialize the app with the `initializeApp(...)` method of the Firebase App plugin first. If not set, the default app is used. | 8.7.0 |


#### WriteBatchOperation

| Prop            | Type                                                  | Description                                                                         | Since |
| --------------- | ----------------------------------------------------- | ----------------------------------------------------------------------------------- | ----- |
| **`type`**      | <code>'set' \| 'update' \| 'delete'</code>            | The type of operation.                                                              | 6.1.0 |
| **`reference`** | <code>string</code>                                   | The reference as a string, with path components separated by a forward slash (`/`). | 6.1.0 |
| **`data`**      | <code><a href="#documentdata">DocumentData</a></code> | An object containing the data for the new document.                                 | 6.1.0 |
| **`options`**   | <code><a href="#setoptions">SetOptions</a></code>     | An object to configure the set behavior.                                            | 7.3.0 |


#### SetOptions

| Prop        | Type                 | Description                                                                | Default            | Since |
| ----------- | -------------------- | -------------------------------------------------------------------------- | ------------------ | ----- |
| **`merge`** | <code>boolean</code> | Whether a merge should be performed or the document should be overwritten. | <code>false</code> | 7.3.0 |


### Type Aliases


#### QueryFilterConstraint

<code><a href="#queryfieldfilterconstraint">QueryFieldFilterConstraint</a> | <a href="#querycompositefilterconstraint">QueryCompositeFilterConstraint</a></code>


#### QueryOperator

<code>'&lt;' | '&lt;=' | '==' | '&gt;=' | '&gt;' | '!=' | 'array-contains' | 'array-contains-any' | 'in' | 'not-in'</code>


#### QueryNonFilterConstraint

<code><a href="#queryorderbyconstraint">QueryOrderByConstraint</a> | <a href="#querylimitconstraint">QueryLimitConstraint</a> | <a href="#querystartatconstraint">QueryStartAtConstraint</a> | <a href="#queryendatconstraint">QueryEndAtConstraint</a></code>


#### OrderByDirection

<code>'desc' | 'asc'</code>


#### AddCollectionGroupSnapshotListenerCallback

<code>(event: <a href="#addcollectiongroupsnapshotlistenercallbackevent">AddCollectionGroupSnapshotListenerCallbackEvent</a>&lt;T&gt; | null, error: any): void</code>


#### AddCollectionGroupSnapshotListenerCallbackEvent

<code><a href="#getcollectiongroupresult">GetCollectionGroupResult</a>&lt;T&gt;</code>


#### CallbackId

<code>string</code>


#### AddCollectionSnapshotListenerCallback

<code>(event: <a href="#addcollectionsnapshotlistenercallbackevent">AddCollectionSnapshotListenerCallbackEvent</a>&lt;T&gt; | null, error: any): void</code>


#### AddCollectionSnapshotListenerCallbackEvent

<code><a href="#getcollectionresult">GetCollectionResult</a>&lt;T&gt;</code>


#### AddDocumentSnapshotListenerCallback

<code>(event: <a href="#adddocumentsnapshotlistenercallbackevent">AddDocumentSnapshotListenerCallbackEvent</a>&lt;T&gt; | null, error: any): void</code>


#### AddDocumentSnapshotListenerCallbackEvent

<code><a href="#getdocumentresult">GetDocumentResult</a>&lt;T&gt;</code>

</docgen-api>

## FAQ

### How do I get notified about data changes in real time?

Attach a snapshot listener with `addDocumentSnapshotListener(...)`, `addCollectionSnapshotListener(...)`, or `addCollectionGroupSnapshotListener(...)`. The callback is invoked whenever the observed data changes. Each listener returns a callback ID that you can later pass to `removeSnapshotListener(...)`, or you can remove all listeners at once with `removeAllListeners()`. See [Listen for real-time updates](#listen-for-real-time-updates) for an example.

### What is the difference between `getCollection` and `getCollectionGroup`?

The `getCollection(...)` method reads the documents of a single collection at the given reference. The `getCollectionGroup(...)` method reads the documents of a collection group, which consists of all collections with the same ID. Both methods support composite filters and query constraints.

### Does the plugin work offline?

Yes, you can enable offline persistence with the `enablePersistence(...)` method, which must be called before any other Firestore method. You can also disable and re-enable the use of the network with `disableNetwork()` and `enableNetwork()`. The persistent storage, including pending writes and cached documents, can be cleared with `clearPersistence()`, which must be called before the first read or write, or after `terminate()`.

### Can I use a Firestore database other than the default one?

Yes, you can set the `databaseId` configuration option in your Capacitor configuration to select the Firestore database to use (see [Configuration](#configuration)). This option is only available on Android and iOS.

### Can I use more than one Firebase project in my app?

Yes. Initialize another app with the `initializeApp(...)` method of the Firebase App plugin and pass its name as `appName` to the Firestore methods. See [Use another Firebase project](#use-another-firebase-project) for an example. The `databaseId` configuration option applies only to calls without `appName`. A call with `appName` always uses the default database of that app.

### How do I test my app against a local Firestore instance?

Use the `useEmulator(...)` method to connect the plugin to a local Firebase Emulator instance by providing its host and port. This allows you to develop and test without touching your production data.

### Can I use this plugin with Ionic, React, Vue or Angular?

Yes, the plugin is framework-agnostic. It works in any Capacitor app regardless of the web framework, including Ionic with Angular, React, or Vue, as well as plain JavaScript projects.

## Related Plugins

- [Firebase Authentication](https://capawesome.io/docs/sdks/capacitor/firebase/authentication/): Unofficial Capacitor plugin for Firebase Authentication.
- [Firebase Cloud Functions](https://capawesome.io/docs/sdks/capacitor/firebase/cloud-functions/): Unofficial Capacitor plugin for Firebase Cloud Functions.
- [Firebase Cloud Storage](https://capawesome.io/docs/sdks/capacitor/firebase/cloud-storage/): Unofficial Capacitor plugin for Firebase Cloud Storage.

## Newsletter

Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our [Capawesome Newsletter](https://cloud.capawesome.io/newsletter/).

## Changelog

See [CHANGELOG.md](https://github.com/capawesome-team/capacitor-firebase/blob/main/packages/firestore/CHANGELOG.md).

## License

See [LICENSE](https://github.com/capawesome-team/capacitor-firebase/blob/main/packages/firestore/LICENSE).

[^1]: This project is not affiliated with, endorsed by, sponsored by, or approved by Google LLC or any of their affiliates or subsidiaries.
