---
description: Unofficial Capacitor plugin for Firebase Cloud Firestore SDK to store and sync data in real-time with support for Android, iOS, and Web.
title: Capacitor Firestore Plugin for Android, iOS & Web - Capawesome
image: https://capawesome.io/docs/assets/images/social/sdks/capacitor/firebase/cloud-firestore.png
---

<!doctype html> 

[Skip to content ](#capacitor-firebasefirestore) 

[🖥️ Introducing the **Capacitor Electron Platform** — build desktop apps for macOS, Windows, and Linux. Free & open source. ](/blog/announcing-the-capacitor-electron-platform/) 

* [ SDKs ](/docs/sdks/)
* [ iOS ](#ios)
* [ Configuration ](#configuration)
* [ Demo ](#demo)
* [ Starter templates ](#starter-templates)
* [ Usage ](#usage)
* [ API ](#api)
* [ Type Aliases ](#type-aliases)
* [ FAQ ](#faq)
* [ Related Plugins ](#related-plugins)
* [ Newsletter ](#newsletter)
* [ Changelog ](#changelog)
* [ License ](#license)
* [ Cloud Functions ](/docs/sdks/capacitor/firebase/cloud-functions/)
* [ Cloud Messaging ](/docs/sdks/capacitor/firebase/cloud-messaging/)
* [ Cloud Storage ](/docs/sdks/capacitor/firebase/cloud-storage/)
* [ Performance Monitoring ](/docs/sdks/capacitor/firebase/performance-monitoring/)
* [ Remote Config ](/docs/sdks/capacitor/firebase/remote-config/)
* [ Formbricks ](/docs/sdks/capacitor/formbricks/)
* [ Geocoder ](/docs/sdks/capacitor/geocoder/)
* [ Google Sign-In ](/docs/sdks/capacitor/google-sign-in/)
* [ Grafana Faro ](/docs/sdks/capacitor/grafana-faro/)
* [ Gyroscope ](/docs/sdks/capacitor/gyroscope/)
* [ Haptics ](/docs/sdks/capacitor/haptics/)
* [ Home Indicator ](/docs/sdks/capacitor/home-indicator/)
* [ In-App Browser ](/docs/sdks/capacitor/in-app-browser/)
* [ Install Referrer ](/docs/sdks/capacitor/install-referrer/)
* [ Intercom ](/docs/sdks/capacitor/intercom/)
* [ Intune ](/docs/sdks/capacitor/intune/)
* [ Keep Awake ](/docs/sdks/capacitor/keep-awake/)
* [ libSQL ](/docs/sdks/capacitor/libsql/)
* [ Light Sensor ](/docs/sdks/capacitor/light-sensor/)
* [ Live Update ](/docs/sdks/capacitor/live-update/)
* [ Localization ](/docs/sdks/capacitor/localization/)
* [ Mail Composer ](/docs/sdks/capacitor/mail-composer/)
* [ Managed Configurations ](/docs/sdks/capacitor/managed-configurations/)
* [ Maps Launcher ](/docs/sdks/capacitor/maps-launcher/)
* [ Media Session ](/docs/sdks/capacitor/media-session/)
* [ ML Kit ](/docs/sdks/capacitor/mlkit/)
* [ Navigation Bar ](/docs/sdks/capacitor/navigation-bar/)
* [ Network ](/docs/sdks/capacitor/network/)
* [ NFC ](/docs/sdks/capacitor/nfc/)
* [ Node.js ](/docs/sdks/capacitor/nodejs/)
* [ OAuth ](/docs/sdks/capacitor/oauth/)
* [ Passkeys ](/docs/sdks/capacitor/passkeys/)
* [ Password Autofill ](/docs/sdks/capacitor/password-autofill/)
* [ PDF Generator ](/docs/sdks/capacitor/pdf-generator/)
* [ PDF Viewer ](/docs/sdks/capacitor/pdf-viewer/)
* [ Pedometer ](/docs/sdks/capacitor/pedometer/)
* [ Permissions ](/docs/sdks/capacitor/permissions/)
* [ Phone Dialer ](/docs/sdks/capacitor/phone-dialer/)
* [ Photo Editor ](/docs/sdks/capacitor/photo-editor/)
* [ Photo Manipulator ](/docs/sdks/capacitor/photo-manipulator/)
* [ PixLive ](/docs/sdks/capacitor/pixlive/)
* [ PostHog ](/docs/sdks/capacitor/posthog/)
* [ Printer ](/docs/sdks/capacitor/printer/)
* [ Privacy Screen ](/docs/sdks/capacitor/privacy-screen/)
* [ Proximity Sensor ](/docs/sdks/capacitor/proximity-sensor/)
* [ Purchases ](/docs/sdks/capacitor/purchases/)
* [ RealtimeKit ](/docs/sdks/capacitor/realtimekit/)
* [ Root Detection ](/docs/sdks/capacitor/root-detection/)
* [ Screen Brightness ](/docs/sdks/capacitor/screen-brightness/)
* [ Screen Orientation ](/docs/sdks/capacitor/screen-orientation/)
* [ Screen Reader ](/docs/sdks/capacitor/screen-reader/)
* [ Screenshot ](/docs/sdks/capacitor/screenshot/)
* [ Secure Preferences ](/docs/sdks/capacitor/secure-preferences/)
* [ Settings Launcher ](/docs/sdks/capacitor/settings-launcher/)
* [ Shake ](/docs/sdks/capacitor/shake/)
* [ Silent Mode ](/docs/sdks/capacitor/silent-mode/)
* [ SIM ](/docs/sdks/capacitor/sim/)
* [ SMS Composer ](/docs/sdks/capacitor/sms-composer/)
* [ Speech Recognition ](/docs/sdks/capacitor/speech-recognition/)
* [ Speech Synthesis ](/docs/sdks/capacitor/speech-synthesis/)
* [ Share Target ](/docs/sdks/capacitor/share-target/)
* [ Square Mobile Payments ](/docs/sdks/capacitor/square-mobile-payments/)
* [ SQLite ](/docs/sdks/capacitor/sqlite/)
* [ Superwall ](/docs/sdks/capacitor/superwall/)
* [ System WebView ](/docs/sdks/capacitor/system-webview/)
* [ Tauri ](/docs/sdks/capacitor/tauri/)
* [ Text Interaction ](/docs/sdks/capacitor/text-interaction/)
* [ Text Zoom ](/docs/sdks/capacitor/text-zoom/)
* [ Thermal State ](/docs/sdks/capacitor/thermal-state/)
* [ Toast ](/docs/sdks/capacitor/toast/)
* [ Torch ](/docs/sdks/capacitor/torch/)
* [ Vault ](/docs/sdks/capacitor/vault/)
* [ Volume ](/docs/sdks/capacitor/volume/)
* [ Wallet ](/docs/sdks/capacitor/wallet/)
* [ Wifi ](/docs/sdks/capacitor/wifi/)
* [ YouTube Player ](/docs/sdks/capacitor/youtube-player/)
* [ Zip ](/docs/sdks/capacitor/zip/)
* [ Cordova ](/docs/sdks/cordova/)
* [ Cloud ](/docs/cloud/)
* [ Integrations ](/docs/cloud/live-updates/integrations/)
* Concepts
* Reference
* [ Troubleshooting ](/docs/cloud/live-updates/troubleshooting/)
* [ FAQ ](/docs/cloud/live-updates/faq/)
* [ Native Builds ](/docs/cloud/native-builds/)
* [ Set Up Environments ](/docs/cloud/native-builds/environments/)
* [ Overwrite Native Configurations ](/docs/cloud/native-builds/native-configurations/)
* [ Auto-Increment Build Numbers ](/docs/cloud/native-builds/auto-incrementing-build-numbers/)
* [ Configure the Web Build Script ](/docs/cloud/native-builds/web-build-script/)
* [ Build from a Monorepo ](/docs/cloud/native-builds/monorepo/)
* [ Use pnpm, Yarn, or bun ](/docs/cloud/native-builds/package-managers/)
* [ Install Private npm Packages ](/docs/cloud/native-builds/npm-private-registry/)
* [ Override the Java Version ](/docs/cloud/native-builds/override-java-version/)
* [ Custom iOS Provisioning Profiles ](/docs/cloud/native-builds/custom-ios-provisioning-profiles/)
* [ Build without Git ](/docs/cloud/native-builds/build-without-git/)
* [ Access Git Behind a Firewall ](/docs/cloud/native-builds/firewall-access/)
* [ Integrations ](/docs/cloud/native-builds/integrations/)
* Reference
* [ Troubleshooting ](/docs/cloud/native-builds/troubleshooting/)
* [ FAQ ](/docs/cloud/native-builds/faq/)
* [ App Store Publishing ](/docs/cloud/app-store-publishing/)
* [ Submit a Build ](/docs/cloud/app-store-publishing/submit-a-build/)
* [ Submit Automatically After a Build ](/docs/cloud/app-store-publishing/submit-automatically/)
* [ Troubleshooting ](/docs/cloud/app-store-publishing/troubleshooting/)
* [ FAQ ](/docs/cloud/app-store-publishing/faq/)
* [ Automations ](/docs/cloud/automations/)
* [ Reference ](/docs/cloud/automations/reference/)
* [ Troubleshooting ](/docs/cloud/automations/troubleshooting/)
* [ FAQ ](/docs/cloud/automations/faq/)
* [ Assist ](/docs/cloud/assist/)
* [ CLI ](/docs/cloud/cli/)
* APIs and SDKs
* [ Webhooks ](/docs/cloud/webhooks/)
* [ Integrations ](/docs/cloud/integrations/)
* Account
* [ Organization ](/docs/cloud/organizations/)
* [ Two-Factor Enforcement ](/docs/cloud/organizations/two-factor-authentication/)
* [ Audit Logs ](/docs/cloud/organizations/audit-logs/)
* [ Billing ](/docs/cloud/organizations/billing/)
* [ License Keys ](/docs/cloud/license-keys/)
* [ AI ](/docs/ai/)
* [ Insiders ](/docs/insiders/)
* [ Billing & Plans ](/docs/insiders/billing-and-plans/)
* [ FAQ ](/docs/insiders/faq/)
* [ License ](https://capawesome.io/legal/eula/)
* [ Support ](/docs/support/)
* [ Contributing ](/docs/contributing/)
* Contributing code
* [ Code of Conduct ](/docs/contributing/code-of-conduct/)
* [ Questions ](https://docs.github.com/en/discussions/collaborating-with-your-community-using-discussions/participating-in-a-discussion#creating-a-discussion)
* [ Blog ](/blog/)
* Categories

* [ iOS ](#ios)
* [ Configuration ](#configuration)
* [ Demo ](#demo)
* [ Starter templates ](#starter-templates)
* [ Usage ](#usage)
* [ API ](#api)
* [ Type Aliases ](#type-aliases)
* [ FAQ ](#faq)
* [ Related Plugins ](#related-plugins)
* [ Newsletter ](#newsletter)
* [ Changelog ](#changelog)
* [ License ](#license)

# @capacitor-firebase/firestore[¶](#capacitor-firebasefirestore "Permanent link")

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

[ ![Deliver Live Updates to your Capacitor app with Capawesome Cloud](../../../../assets/external/cloud.capawesome.io/assets/banners/cloud-build-and-deploy-capacitor-apps.69628c3f.png) ](https://cloud.capawesome.io/) 

## Use Cases[¶](#use-cases "Permanent link")

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(...)`.

## Guides[¶](#guides "Permanent link")

* [Announcing the Capacitor Firebase Cloud Firestore Plugin](https://capawesome.io/blog/announcing-the-capacitor-firebase-cloud-firestore-plugin/)

## Compatibility[¶](#compatibility "Permanent link")

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

## Installation[¶](#installation "Permanent link")

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:

`[](#%5F%5Fcodelineno-0-1)npx skills add capawesome-team/skills --skill capacitor-plugins
`

Then use the following prompt:

`` [](#%5F%5Fcodelineno-1-1)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:

`[](#%5F%5Fcodelineno-2-1)npm install @capacitor-firebase/firestore
[](#%5F%5Fcodelineno-2-2)npx cap sync
`

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[¶](#android "Permanent link")

#### Variables[¶](#variables "Permanent link")

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: `26.0.2`)

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

### iOS[¶](#ios "Permanent link")

#### Swift Package Manager[¶](#swift-package-manager "Permanent link")

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):

`[](#%5F%5Fcodelineno-3-1){
[](#%5F%5Fcodelineno-3-2)  "experimental": {
[](#%5F%5Fcodelineno-3-3)    "ios": {
[](#%5F%5Fcodelineno-3-4)      "spm": {
[](#%5F%5Fcodelineno-3-5)        "packageOptions": {
[](#%5F%5Fcodelineno-3-6)          "@capacitor-firebase/firestore": {
[](#%5F%5Fcodelineno-3-7)            "symlink": true
[](#%5F%5Fcodelineno-3-8)          }
[](#%5F%5Fcodelineno-3-9)        }
[](#%5F%5Fcodelineno-3-10)      }
[](#%5F%5Fcodelineno-3-11)    }
[](#%5F%5Fcodelineno-3-12)  }
[](#%5F%5Fcodelineno-3-13)}
`

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

## Configuration[¶](#configuration "Permanent link")

These configuration values are available:

| Prop           | Type   | Description                                                                           | Since |
| -------------- | ------ | ------------------------------------------------------------------------------------- | ----- |
| **databaseId** | string | The database ID of the Firestore database to use. Only available for Android and iOS. | 8.2.0 |

### Examples[¶](#examples "Permanent link")

In `capacitor.config.json`:

`[](#%5F%5Fcodelineno-4-1){
[](#%5F%5Fcodelineno-4-2)  "plugins": {
[](#%5F%5Fcodelineno-4-3)    "FirebaseFirestore": {
[](#%5F%5Fcodelineno-4-4)      "databaseId": undefined
[](#%5F%5Fcodelineno-4-5)    }
[](#%5F%5Fcodelineno-4-6)  }
[](#%5F%5Fcodelineno-4-7)}
`

In `capacitor.config.ts`:

`[](#%5F%5Fcodelineno-5-1)/// <reference types="@capacitor-firebase/firestore" />
[](#%5F%5Fcodelineno-5-2)
[](#%5F%5Fcodelineno-5-3)import { CapacitorConfig } from '@capacitor/cli';
[](#%5F%5Fcodelineno-5-4)
[](#%5F%5Fcodelineno-5-5)const config: CapacitorConfig = {
[](#%5F%5Fcodelineno-5-6)  plugins: {
[](#%5F%5Fcodelineno-5-7)    FirebaseFirestore: {
[](#%5F%5Fcodelineno-5-8)      databaseId: undefined,
[](#%5F%5Fcodelineno-5-9)    },
[](#%5F%5Fcodelineno-5-10)  },
[](#%5F%5Fcodelineno-5-11)};
[](#%5F%5Fcodelineno-5-12)
[](#%5F%5Fcodelineno-5-13)export default config;
`

## Demo[¶](#demo "Permanent link")

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

## Starter templates[¶](#starter-templates "Permanent link")

The following starter templates are available:

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

## Usage[¶](#usage "Permanent link")

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[¶](#create-a-document "Permanent link")

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:

`[](#%5F%5Fcodelineno-6-1)import { FirebaseFirestore } from '@capacitor-firebase/firestore';
[](#%5F%5Fcodelineno-6-2)
[](#%5F%5Fcodelineno-6-3)const addDocument = async () => {
[](#%5F%5Fcodelineno-6-4)  await FirebaseFirestore.addDocument({
[](#%5F%5Fcodelineno-6-5)    reference: 'users',
[](#%5F%5Fcodelineno-6-6)    data: { 
[](#%5F%5Fcodelineno-6-7)      first: 'Alan', 
[](#%5F%5Fcodelineno-6-8)      last: 'Turing', 
[](#%5F%5Fcodelineno-6-9)      born: 1912 
[](#%5F%5Fcodelineno-6-10)    },
[](#%5F%5Fcodelineno-6-11)  });
[](#%5F%5Fcodelineno-6-12)};
[](#%5F%5Fcodelineno-6-13)
[](#%5F%5Fcodelineno-6-14)const setDocument = async () => {
[](#%5F%5Fcodelineno-6-15)  await FirebaseFirestore.setDocument({
[](#%5F%5Fcodelineno-6-16)    reference: 'users/Aorq09lkt1ynbR7xhTUx',
[](#%5F%5Fcodelineno-6-17)    data: { 
[](#%5F%5Fcodelineno-6-18)      first: 'Alan', 
[](#%5F%5Fcodelineno-6-19)      last: 'Turing', 
[](#%5F%5Fcodelineno-6-20)      born: 1912 
[](#%5F%5Fcodelineno-6-21)    },
[](#%5F%5Fcodelineno-6-22)    merge: true,
[](#%5F%5Fcodelineno-6-23)  });
[](#%5F%5Fcodelineno-6-24)};
`

### Read a document[¶](#read-a-document "Permanent link")

Read a single document by its reference:

`[](#%5F%5Fcodelineno-7-1)import { FirebaseFirestore } from '@capacitor-firebase/firestore';
[](#%5F%5Fcodelineno-7-2)
[](#%5F%5Fcodelineno-7-3)const getDocument = async () => {
[](#%5F%5Fcodelineno-7-4)  const { snapshot } = await FirebaseFirestore.getDocument({
[](#%5F%5Fcodelineno-7-5)    reference: 'users/Aorq09lkt1ynbR7xhTUx',
[](#%5F%5Fcodelineno-7-6)  });
[](#%5F%5Fcodelineno-7-7)  return snapshot;
[](#%5F%5Fcodelineno-7-8)};
`

### Update or delete a document[¶](#update-or-delete-a-document "Permanent link")

Update fields of an existing document or delete it entirely:

`[](#%5F%5Fcodelineno-8-1)import { FirebaseFirestore } from '@capacitor-firebase/firestore';
[](#%5F%5Fcodelineno-8-2)
[](#%5F%5Fcodelineno-8-3)const updateDocument = async () => {
[](#%5F%5Fcodelineno-8-4)  await FirebaseFirestore.updateDocument({
[](#%5F%5Fcodelineno-8-5)    reference: 'users/Aorq09lkt1ynbR7xhTUx',
[](#%5F%5Fcodelineno-8-6)    data: { 
[](#%5F%5Fcodelineno-8-7)      first: 'Alan', 
[](#%5F%5Fcodelineno-8-8)      last: 'Turing', 
[](#%5F%5Fcodelineno-8-9)      born: 1912 
[](#%5F%5Fcodelineno-8-10)    },
[](#%5F%5Fcodelineno-8-11)  });
[](#%5F%5Fcodelineno-8-12)};
[](#%5F%5Fcodelineno-8-13)
[](#%5F%5Fcodelineno-8-14)const deleteDocument = async () => {
[](#%5F%5Fcodelineno-8-15)  await FirebaseFirestore.deleteDocument({
[](#%5F%5Fcodelineno-8-16)    reference: 'users/Aorq09lkt1ynbR7xhTUx',
[](#%5F%5Fcodelineno-8-17)  });
[](#%5F%5Fcodelineno-8-18)};
`

### Update a document with field values[¶](#update-a-document-with-field-values "Permanent link")

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

`[](#%5F%5Fcodelineno-9-1)import { FieldValue, FirebaseFirestore } from '@capacitor-firebase/firestore';
[](#%5F%5Fcodelineno-9-2)
[](#%5F%5Fcodelineno-9-3)const updateDocumentWithFieldValue = async () => {
[](#%5F%5Fcodelineno-9-4)  await FirebaseFirestore.updateDocument({
[](#%5F%5Fcodelineno-9-5)    reference: 'users/Aorq09lkt1ynbR7xhTUx',
[](#%5F%5Fcodelineno-9-6)    data: {
[](#%5F%5Fcodelineno-9-7)      born: FieldValue.increment(1),
[](#%5F%5Fcodelineno-9-8)      updatedAt: FieldValue.serverTimestamp(),
[](#%5F%5Fcodelineno-9-9)      nicknames: FieldValue.arrayUnion('Prof'),
[](#%5F%5Fcodelineno-9-10)      tags: FieldValue.arrayRemove('draft'),
[](#%5F%5Fcodelineno-9-11)      deprecatedField: FieldValue.delete(),
[](#%5F%5Fcodelineno-9-12)    },
[](#%5F%5Fcodelineno-9-13)  });
[](#%5F%5Fcodelineno-9-14)};
`

### Perform a batched write[¶](#perform-a-batched-write "Permanent link")

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

`[](#%5F%5Fcodelineno-10-1)import { FirebaseFirestore } from '@capacitor-firebase/firestore';
[](#%5F%5Fcodelineno-10-2)
[](#%5F%5Fcodelineno-10-3)const writeBatch = async () => {
[](#%5F%5Fcodelineno-10-4)  await FirebaseFirestore.writeBatch({
[](#%5F%5Fcodelineno-10-5)    operations: [
[](#%5F%5Fcodelineno-10-6)      {
[](#%5F%5Fcodelineno-10-7)        type: 'set',
[](#%5F%5Fcodelineno-10-8)        reference: 'users/Aorq09lkt1ynbR7xhTUx',
[](#%5F%5Fcodelineno-10-9)        data: { 
[](#%5F%5Fcodelineno-10-10)          first: 'Alan', 
[](#%5F%5Fcodelineno-10-11)          last: 'Turing', 
[](#%5F%5Fcodelineno-10-12)          born: 1912 
[](#%5F%5Fcodelineno-10-13)        },
[](#%5F%5Fcodelineno-10-14)        options: { merge: true },
[](#%5F%5Fcodelineno-10-15)      },
[](#%5F%5Fcodelineno-10-16)      {
[](#%5F%5Fcodelineno-10-17)        type: 'update',
[](#%5F%5Fcodelineno-10-18)        reference: 'users/Aorq09lkt1ynbR7xhTUx',
[](#%5F%5Fcodelineno-10-19)        data: { 
[](#%5F%5Fcodelineno-10-20)          first: 'Alan', 
[](#%5F%5Fcodelineno-10-21)          last: 'Turing', 
[](#%5F%5Fcodelineno-10-22)          born: 1912 
[](#%5F%5Fcodelineno-10-23)        },
[](#%5F%5Fcodelineno-10-24)      },
[](#%5F%5Fcodelineno-10-25)      {
[](#%5F%5Fcodelineno-10-26)        type: 'delete',
[](#%5F%5Fcodelineno-10-27)        reference: 'users/Aorq09lkt1ynbR7xhTUx',
[](#%5F%5Fcodelineno-10-28)      },
[](#%5F%5Fcodelineno-10-29)    ],
[](#%5F%5Fcodelineno-10-30)  });
[](#%5F%5Fcodelineno-10-31)};
`

### Query a collection[¶](#query-a-collection "Permanent link")

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`:

`[](#%5F%5Fcodelineno-11-1)import { FirebaseFirestore } from '@capacitor-firebase/firestore';
[](#%5F%5Fcodelineno-11-2)
[](#%5F%5Fcodelineno-11-3)const getCollection = async () => {
[](#%5F%5Fcodelineno-11-4)  const { snapshots } = await FirebaseFirestore.getCollection({
[](#%5F%5Fcodelineno-11-5)    reference: 'users',
[](#%5F%5Fcodelineno-11-6)    compositeFilter: {
[](#%5F%5Fcodelineno-11-7)      type: 'and',
[](#%5F%5Fcodelineno-11-8)      queryConstraints: [
[](#%5F%5Fcodelineno-11-9)        {
[](#%5F%5Fcodelineno-11-10)          type: 'where',
[](#%5F%5Fcodelineno-11-11)          fieldPath: 'born',
[](#%5F%5Fcodelineno-11-12)          opStr: '==',
[](#%5F%5Fcodelineno-11-13)          value: 1912,
[](#%5F%5Fcodelineno-11-14)        },
[](#%5F%5Fcodelineno-11-15)      ],
[](#%5F%5Fcodelineno-11-16)    },
[](#%5F%5Fcodelineno-11-17)    queryConstraints: [
[](#%5F%5Fcodelineno-11-18)      {
[](#%5F%5Fcodelineno-11-19)        type: 'orderBy',
[](#%5F%5Fcodelineno-11-20)        fieldPath: 'born',
[](#%5F%5Fcodelineno-11-21)        directionStr: 'desc',
[](#%5F%5Fcodelineno-11-22)      },
[](#%5F%5Fcodelineno-11-23)      {
[](#%5F%5Fcodelineno-11-24)        type: 'limit',
[](#%5F%5Fcodelineno-11-25)        limit: 10,
[](#%5F%5Fcodelineno-11-26)      },
[](#%5F%5Fcodelineno-11-27)    ],
[](#%5F%5Fcodelineno-11-28)  });
[](#%5F%5Fcodelineno-11-29)  return snapshots;
[](#%5F%5Fcodelineno-11-30)};
[](#%5F%5Fcodelineno-11-31)
[](#%5F%5Fcodelineno-11-32)const getCollectionGroup = async () => {
[](#%5F%5Fcodelineno-11-33)  const { snapshots } = await FirebaseFirestore.getCollectionGroup({
[](#%5F%5Fcodelineno-11-34)    reference: 'users',
[](#%5F%5Fcodelineno-11-35)    compositeFilter: {
[](#%5F%5Fcodelineno-11-36)      type: 'and',
[](#%5F%5Fcodelineno-11-37)      queryConstraints: [
[](#%5F%5Fcodelineno-11-38)        {
[](#%5F%5Fcodelineno-11-39)          type: 'where',
[](#%5F%5Fcodelineno-11-40)          fieldPath: 'born',
[](#%5F%5Fcodelineno-11-41)          opStr: '==',
[](#%5F%5Fcodelineno-11-42)          value: 1912,
[](#%5F%5Fcodelineno-11-43)        },
[](#%5F%5Fcodelineno-11-44)      ],
[](#%5F%5Fcodelineno-11-45)    },
[](#%5F%5Fcodelineno-11-46)    queryConstraints: [
[](#%5F%5Fcodelineno-11-47)      {
[](#%5F%5Fcodelineno-11-48)        type: 'orderBy',
[](#%5F%5Fcodelineno-11-49)        fieldPath: 'born',
[](#%5F%5Fcodelineno-11-50)        directionStr: 'desc',
[](#%5F%5Fcodelineno-11-51)      },
[](#%5F%5Fcodelineno-11-52)      {
[](#%5F%5Fcodelineno-11-53)        type: 'limit',
[](#%5F%5Fcodelineno-11-54)        limit: 10,
[](#%5F%5Fcodelineno-11-55)      },
[](#%5F%5Fcodelineno-11-56)    ],
[](#%5F%5Fcodelineno-11-57)  });
[](#%5F%5Fcodelineno-11-58)  return snapshots;
[](#%5F%5Fcodelineno-11-59)};
`

### Control network access[¶](#control-network-access "Permanent link")

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

`[](#%5F%5Fcodelineno-12-1)import { FirebaseFirestore } from '@capacitor-firebase/firestore';
[](#%5F%5Fcodelineno-12-2)
[](#%5F%5Fcodelineno-12-3)const enableNetwork = async () => {
[](#%5F%5Fcodelineno-12-4)  await FirebaseFirestore.enableNetwork();
[](#%5F%5Fcodelineno-12-5)};
[](#%5F%5Fcodelineno-12-6)
[](#%5F%5Fcodelineno-12-7)const disableNetwork = async () => {
[](#%5F%5Fcodelineno-12-8)  await FirebaseFirestore.disableNetwork();
[](#%5F%5Fcodelineno-12-9)};
`

### Use the Firebase Emulator[¶](#use-the-firebase-emulator "Permanent link")

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

`[](#%5F%5Fcodelineno-13-1)import { FirebaseFirestore } from '@capacitor-firebase/firestore';
[](#%5F%5Fcodelineno-13-2)
[](#%5F%5Fcodelineno-13-3)const useEmulator = async () => {
[](#%5F%5Fcodelineno-13-4)  await FirebaseFirestore.useEmulator({
[](#%5F%5Fcodelineno-13-5)    host: '10.0.2.2',
[](#%5F%5Fcodelineno-13-6)    port: 9001,
[](#%5F%5Fcodelineno-13-7)  });
[](#%5F%5Fcodelineno-13-8)};
`

### Listen for real-time updates[¶](#listen-for-real-time-updates "Permanent link")

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

`[](#%5F%5Fcodelineno-14-1)import { FirebaseFirestore } from '@capacitor-firebase/firestore';
[](#%5F%5Fcodelineno-14-2)
[](#%5F%5Fcodelineno-14-3)const addDocumentSnapshotListener = async () => {
[](#%5F%5Fcodelineno-14-4)  const callbackId = await FirebaseFirestore.addDocumentSnapshotListener(
[](#%5F%5Fcodelineno-14-5)    {
[](#%5F%5Fcodelineno-14-6)      reference: 'users/Aorq09lkt1ynbR7xhTUx',
[](#%5F%5Fcodelineno-14-7)    },
[](#%5F%5Fcodelineno-14-8)    (event, error) => {
[](#%5F%5Fcodelineno-14-9)      if (error) {
[](#%5F%5Fcodelineno-14-10)        console.error(error);
[](#%5F%5Fcodelineno-14-11)      } else {
[](#%5F%5Fcodelineno-14-12)        console.log(event);
[](#%5F%5Fcodelineno-14-13)      }
[](#%5F%5Fcodelineno-14-14)    }
[](#%5F%5Fcodelineno-14-15)  );
[](#%5F%5Fcodelineno-14-16)  return callbackId;
[](#%5F%5Fcodelineno-14-17)};
[](#%5F%5Fcodelineno-14-18)
[](#%5F%5Fcodelineno-14-19)const addCollectionSnapshotListener = async () => {
[](#%5F%5Fcodelineno-14-20)  const callbackId = await FirebaseFirestore.addCollectionSnapshotListener(
[](#%5F%5Fcodelineno-14-21)    {
[](#%5F%5Fcodelineno-14-22)      reference: 'users',
[](#%5F%5Fcodelineno-14-23)      compositeFilter: {
[](#%5F%5Fcodelineno-14-24)        type: 'and',
[](#%5F%5Fcodelineno-14-25)        queryConstraints: [
[](#%5F%5Fcodelineno-14-26)          {
[](#%5F%5Fcodelineno-14-27)            type: 'where',
[](#%5F%5Fcodelineno-14-28)            fieldPath: 'born',
[](#%5F%5Fcodelineno-14-29)            opStr: '==',
[](#%5F%5Fcodelineno-14-30)            value: 1912,
[](#%5F%5Fcodelineno-14-31)          },
[](#%5F%5Fcodelineno-14-32)        ],
[](#%5F%5Fcodelineno-14-33)      },
[](#%5F%5Fcodelineno-14-34)      queryConstraints: [
[](#%5F%5Fcodelineno-14-35)        {
[](#%5F%5Fcodelineno-14-36)          type: 'orderBy',
[](#%5F%5Fcodelineno-14-37)          fieldPath: 'born',
[](#%5F%5Fcodelineno-14-38)          directionStr: 'desc',
[](#%5F%5Fcodelineno-14-39)        },
[](#%5F%5Fcodelineno-14-40)        {
[](#%5F%5Fcodelineno-14-41)          type: 'limit',
[](#%5F%5Fcodelineno-14-42)          limit: 10,
[](#%5F%5Fcodelineno-14-43)        },
[](#%5F%5Fcodelineno-14-44)      ],
[](#%5F%5Fcodelineno-14-45)    },
[](#%5F%5Fcodelineno-14-46)    (event, error) => {
[](#%5F%5Fcodelineno-14-47)      if (error) {
[](#%5F%5Fcodelineno-14-48)        console.error(error);
[](#%5F%5Fcodelineno-14-49)      } else {
[](#%5F%5Fcodelineno-14-50)        console.log(event);
[](#%5F%5Fcodelineno-14-51)      }
[](#%5F%5Fcodelineno-14-52)    }
[](#%5F%5Fcodelineno-14-53)  );
[](#%5F%5Fcodelineno-14-54)  return callbackId;
[](#%5F%5Fcodelineno-14-55)};
[](#%5F%5Fcodelineno-14-56)
[](#%5F%5Fcodelineno-14-57)const addCollectionGroupSnapshotListener = async () => {
[](#%5F%5Fcodelineno-14-58)  const callbackId = await FirebaseFirestore.addCollectionGroupSnapshotListener(
[](#%5F%5Fcodelineno-14-59)    {
[](#%5F%5Fcodelineno-14-60)      reference: 'users',
[](#%5F%5Fcodelineno-14-61)      compositeFilter: {
[](#%5F%5Fcodelineno-14-62)        type: 'and',
[](#%5F%5Fcodelineno-14-63)        queryConstraints: [
[](#%5F%5Fcodelineno-14-64)          {
[](#%5F%5Fcodelineno-14-65)            type: 'where',
[](#%5F%5Fcodelineno-14-66)            fieldPath: 'born',
[](#%5F%5Fcodelineno-14-67)            opStr: '==',
[](#%5F%5Fcodelineno-14-68)            value: 1912,
[](#%5F%5Fcodelineno-14-69)          },
[](#%5F%5Fcodelineno-14-70)        ],
[](#%5F%5Fcodelineno-14-71)      },
[](#%5F%5Fcodelineno-14-72)      queryConstraints: [
[](#%5F%5Fcodelineno-14-73)        {
[](#%5F%5Fcodelineno-14-74)          type: 'orderBy',
[](#%5F%5Fcodelineno-14-75)          fieldPath: 'born',
[](#%5F%5Fcodelineno-14-76)          directionStr: 'desc',
[](#%5F%5Fcodelineno-14-77)        },
[](#%5F%5Fcodelineno-14-78)        {
[](#%5F%5Fcodelineno-14-79)          type: 'limit',
[](#%5F%5Fcodelineno-14-80)          limit: 10,
[](#%5F%5Fcodelineno-14-81)        },
[](#%5F%5Fcodelineno-14-82)      ],
[](#%5F%5Fcodelineno-14-83)    },
[](#%5F%5Fcodelineno-14-84)    (event, error) => {
[](#%5F%5Fcodelineno-14-85)      if (error) {
[](#%5F%5Fcodelineno-14-86)        console.error(error);
[](#%5F%5Fcodelineno-14-87)      } else {
[](#%5F%5Fcodelineno-14-88)        console.log(event);
[](#%5F%5Fcodelineno-14-89)      }
[](#%5F%5Fcodelineno-14-90)    }
[](#%5F%5Fcodelineno-14-91)  );
[](#%5F%5Fcodelineno-14-92)  return callbackId;
[](#%5F%5Fcodelineno-14-93)};
`

### Remove listeners[¶](#remove-listeners "Permanent link")

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

`[](#%5F%5Fcodelineno-15-1)import { FirebaseFirestore } from '@capacitor-firebase/firestore';
[](#%5F%5Fcodelineno-15-2)
[](#%5F%5Fcodelineno-15-3)const removeSnapshotListener = async (callbackId: string) => {
[](#%5F%5Fcodelineno-15-4)  await FirebaseFirestore.removeSnapshotListener({
[](#%5F%5Fcodelineno-15-5)    callbackId,
[](#%5F%5Fcodelineno-15-6)  });
[](#%5F%5Fcodelineno-15-7)};
[](#%5F%5Fcodelineno-15-8)
[](#%5F%5Fcodelineno-15-9)const removeAllListeners = async () => {
[](#%5F%5Fcodelineno-15-10)  await FirebaseFirestore.removeAllListeners();
[](#%5F%5Fcodelineno-15-11)};
`

## API[¶](#api "Permanent link")

* [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)
* [updateDocument(...)](#updatedocument)
* [useEmulator(...)](#useemulator)
* [writeBatch(...)](#writebatch)
* [Interfaces](#interfaces)
* [Type Aliases](#type-aliases)

### addDocument(...)[¶](#adddocument "Permanent link")

`[](#%5F%5Fcodelineno-16-1)addDocument(options: AddDocumentOptions) => Promise<AddDocumentResult>
`

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

| Param       | Type                                      |
| ----------- | ----------------------------------------- |
| **options** | [AddDocumentOptions](#adddocumentoptions) |

**Returns:** `Promise<[AddDocumentResult](#adddocumentresult)>`

**Since:** 5.2.0

---

### addCollectionGroupSnapshotListener(...)[¶](#addcollectiongroupsnapshotlistener "Permanent link")

`[](#%5F%5Fcodelineno-17-1)addCollectionGroupSnapshotListener<T extends DocumentData = DocumentData>(options: AddCollectionGroupSnapshotListenerOptions, callback: AddCollectionGroupSnapshotListenerCallback<T>) => Promise<CallbackId>
`

Adds a listener for collection group snapshot events.

| Param        | Type                                                                                         |
| ------------ | -------------------------------------------------------------------------------------------- |
| **options**  | [AddCollectionGroupSnapshotListenerOptions](#addcollectiongroupsnapshotlisteneroptions)      |
| **callback** | [AddCollectionGroupSnapshotListenerCallback](#addcollectiongroupsnapshotlistenercallback)<T> |

**Returns:** `Promise<string>`

**Since:** 6.1.0

---

### addCollectionSnapshotListener(...)[¶](#addcollectionsnapshotlistener "Permanent link")

`[](#%5F%5Fcodelineno-18-1)addCollectionSnapshotListener<T extends DocumentData = DocumentData>(options: AddCollectionSnapshotListenerOptions, callback: AddCollectionSnapshotListenerCallback<T>) => Promise<CallbackId>
`

Adds a listener for collection snapshot events.

| Param        | Type                                                                               |
| ------------ | ---------------------------------------------------------------------------------- |
| **options**  | [AddCollectionSnapshotListenerOptions](#addcollectionsnapshotlisteneroptions)      |
| **callback** | [AddCollectionSnapshotListenerCallback](#addcollectionsnapshotlistenercallback)<T> |

**Returns:** `Promise<string>`

**Since:** 5.2.0

---

### addDocumentSnapshotListener(...)[¶](#adddocumentsnapshotlistener "Permanent link")

`[](#%5F%5Fcodelineno-19-1)addDocumentSnapshotListener<T extends DocumentData = DocumentData>(options: AddDocumentSnapshotListenerOptions, callback: AddDocumentSnapshotListenerCallback<T>) => Promise<CallbackId>
`

Adds a listener for document snapshot events.

| Param        | Type                                                                           |
| ------------ | ------------------------------------------------------------------------------ |
| **options**  | [AddDocumentSnapshotListenerOptions](#adddocumentsnapshotlisteneroptions)      |
| **callback** | [AddDocumentSnapshotListenerCallback](#adddocumentsnapshotlistenercallback)<T> |

**Returns:** `Promise<string>`

**Since:** 5.2.0

---

### clearPersistence()[¶](#clearpersistence "Permanent link")

`[](#%5F%5Fcodelineno-20-1)clearPersistence() => Promise<void>
`

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

**Attention**: Must be called after the app is shutdown or when the app is first initialized.

**Since:** 5.2.0

---

### deleteDocument(...)[¶](#deletedocument "Permanent link")

`[](#%5F%5Fcodelineno-21-1)deleteDocument(options: DeleteDocumentOptions) => Promise<void>
`

Deletes the document referred to by the specified reference.

| Param       | Type                                            |
| ----------- | ----------------------------------------------- |
| **options** | [DeleteDocumentOptions](#deletedocumentoptions) |

**Since:** 5.2.0

---

### disableNetwork()[¶](#disablenetwork "Permanent link")

`[](#%5F%5Fcodelineno-22-1)disableNetwork() => Promise<void>
`

Disables use of the network.

**Since:** 5.2.0

---

### disablePersistence()[¶](#disablepersistence "Permanent link")

`[](#%5F%5Fcodelineno-23-1)disablePersistence() => Promise<void>
`

Disables offline persistence.

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

**Since:** 8.2.0

---

### enablePersistence(...)[¶](#enablepersistence "Permanent link")

`[](#%5F%5Fcodelineno-24-1)enablePersistence(options?: EnablePersistenceOptions | undefined) => Promise<void>
`

Enables offline persistence.

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

| Param       | Type                                                  |
| ----------- | ----------------------------------------------------- |
| **options** | [EnablePersistenceOptions](#enablepersistenceoptions) |

**Since:** 8.2.0

---

### enableNetwork()[¶](#enablenetwork "Permanent link")

`[](#%5F%5Fcodelineno-25-1)enableNetwork() => Promise<void>
`

Re-enables use of the network.

**Since:** 5.2.0

---

### getCollection(...)[¶](#getcollection "Permanent link")

`[](#%5F%5Fcodelineno-26-1)getCollection<T extends DocumentData = DocumentData>(options: GetCollectionOptions) => Promise<GetCollectionResult<T>>
`

Reads the collection referenced by the specified reference.

| Param       | Type                                          |
| ----------- | --------------------------------------------- |
| **options** | [GetCollectionOptions](#getcollectionoptions) |

**Returns:** `Promise<[GetCollectionResult](#getcollectionresult)<T>>`

**Since:** 5.2.0

---

### getCollectionGroup(...)[¶](#getcollectiongroup "Permanent link")

`[](#%5F%5Fcodelineno-27-1)getCollectionGroup<T extends DocumentData = DocumentData>(options: GetCollectionGroupOptions) => Promise<GetCollectionGroupResult<T>>
`

Reads the collection group referenced by the specified reference.

| Param       | Type                                                    |
| ----------- | ------------------------------------------------------- |
| **options** | [GetCollectionGroupOptions](#getcollectiongroupoptions) |

**Returns:** `Promise<[GetCollectionGroupResult](#getcollectiongroupresult)<T>>`

---

### getCountFromServer(...)[¶](#getcountfromserver "Permanent link")

`[](#%5F%5Fcodelineno-28-1)getCountFromServer(options: GetCountFromServerOptions) => Promise<GetCountFromServerResult>
`

Fetches the number of documents in a collection.

| Param       | Type                                                    |
| ----------- | ------------------------------------------------------- |
| **options** | [GetCountFromServerOptions](#getcountfromserveroptions) |

**Returns:** `Promise<[GetCountFromServerResult](#getcountfromserverresult)>`

**Since:** 6.4.0

---

### getDocument(...)[¶](#getdocument "Permanent link")

`[](#%5F%5Fcodelineno-29-1)getDocument<T extends DocumentData = DocumentData>(options: GetDocumentOptions) => Promise<GetDocumentResult<T>>
`

Reads the document referred to by the specified reference.

| Param       | Type                                      |
| ----------- | ----------------------------------------- |
| **options** | [GetDocumentOptions](#getdocumentoptions) |

**Returns:** `Promise<[GetDocumentResult](#getdocumentresult)<T>>`

**Since:** 5.2.0

---

### removeAllListeners()[¶](#removealllisteners "Permanent link")

`[](#%5F%5Fcodelineno-30-1)removeAllListeners() => Promise<void>
`

Remove all listeners for this plugin.

**Since:** 5.2.0

---

### removeSnapshotListener(...)[¶](#removesnapshotlistener "Permanent link")

`[](#%5F%5Fcodelineno-31-1)removeSnapshotListener(options: RemoveSnapshotListenerOptions) => Promise<void>
`

Remove a listener for document or collection snapshot events.

| Param       | Type                                                            |
| ----------- | --------------------------------------------------------------- |
| **options** | [RemoveSnapshotListenerOptions](#removesnapshotlisteneroptions) |

**Since:** 5.2.0

---

### setDocument(...)[¶](#setdocument "Permanent link")

`[](#%5F%5Fcodelineno-32-1)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** | [SetDocumentOptions](#setdocumentoptions) |

**Since:** 5.2.0

---

### updateDocument(...)[¶](#updatedocument "Permanent link")

`[](#%5F%5Fcodelineno-33-1)updateDocument(options: UpdateDocumentOptions) => Promise<void>
`

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

| Param       | Type                                            |
| ----------- | ----------------------------------------------- |
| **options** | [UpdateDocumentOptions](#updatedocumentoptions) |

**Since:** 5.2.0

---

### useEmulator(...)[¶](#useemulator "Permanent link")

`[](#%5F%5Fcodelineno-34-1)useEmulator(options: UseEmulatorOptions) => Promise<void>
`

Instrument your app to talk to the Firestore emulator.

| Param       | Type                                      |
| ----------- | ----------------------------------------- |
| **options** | [UseEmulatorOptions](#useemulatoroptions) |

**Since:** 6.1.0

---

### writeBatch(...)[¶](#writebatch "Permanent link")

`[](#%5F%5Fcodelineno-35-1)writeBatch(options: WriteBatchOptions) => Promise<void>
`

Execute multiple write operations as a single batch.

| Param       | Type                                    |
| ----------- | --------------------------------------- |
| **options** | [WriteBatchOptions](#writebatchoptions) |

**Since:** 6.1.0

---

### Interfaces[¶](#interfaces "Permanent link")

#### AddDocumentResult[¶](#adddocumentresult "Permanent link")

| Prop          | Type              | Description                                | Since |
| ------------- | ----------------- | ------------------------------------------ | ----- |
| **reference** | DocumentReference | The reference of the newly added document. | 5.2.0 |

#### AddDocumentOptions[¶](#adddocumentoptions "Permanent link")

| Prop          | Type                          | Description                                                                       | Since |
| ------------- | ----------------------------- | --------------------------------------------------------------------------------- | ----- |
| **reference** | string                        | The reference as a string, with path components separated by a forward slash (/). | 5.2.0 |
| **data**      | [DocumentData](#documentdata) | An object containing the data for the new document.                               | 5.2.0 |

#### DocumentData[¶](#documentdata "Permanent link")

#### AddCollectionGroupSnapshotListenerOptions[¶](#addcollectiongroupsnapshotlisteneroptions "Permanent link")

| Prop                 | Type                                                              | Description                                                                                         | Since |
| -------------------- | ----------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | ----- |
| **reference**        | string                                                            | The reference as a string, with path components separated by a forward slash (/).                   | 6.1.0 |
| **compositeFilter**  | [QueryCompositeFilterConstraint](#querycompositefilterconstraint) | The filter to apply.                                                                                | 6.1.0 |
| **queryConstraints** | QueryNonFilterConstraint\[\]                                      | Narrow or order the set of documents to retrieve, but do not explicitly filter for document fields. | 6.1.0 |

#### QueryCompositeFilterConstraint[¶](#querycompositefilterconstraint "Permanent link")

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

#### QueryFieldFilterConstraint[¶](#queryfieldfilterconstraint "Permanent link")

| Prop          | Type                            | Description                    | Since |
| ------------- | ------------------------------- | ------------------------------ | ----- |
| **type**      | 'where'                         | The type of the constraint.    | 5.2.0 |
| **fieldPath** | string                          | The path to compare.           | 5.2.0 |
| **opStr**     | [QueryOperator](#queryoperator) | The operation string to apply. | 5.2.0 |
| **value**     | any                             | The value for comparison.      | 5.2.0 |

#### QueryOrderByConstraint[¶](#queryorderbyconstraint "Permanent link")

| Prop             | Type                                  | Description                 | Since |
| ---------------- | ------------------------------------- | --------------------------- | ----- |
| **type**         | 'orderBy'                             | The type of the constraint. | 5.2.0 |
| **fieldPath**    | string                                | The path to compare.        | 5.2.0 |
| **directionStr** | [OrderByDirection](#orderbydirection) | The direction to sort by.   | 5.2.0 |

#### QueryLimitConstraint[¶](#querylimitconstraint "Permanent link")

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

#### QueryStartAtConstraint[¶](#querystartatconstraint "Permanent link")

| Prop          | Type                      | Description                                                                                                                                                      | Since |
| ------------- | ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
| **type**      | 'startAt' \| 'startAfter' | The type of the constraint.                                                                                                                                      | 5.2.0 |
| **reference** | string                    | 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[¶](#queryendatconstraint "Permanent link")

| Prop          | Type                   | Description                                                                                                                                                        | Since |
| ------------- | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----- |
| **type**      | 'endAt' \| 'endBefore' | The type of the constraint.                                                                                                                                        | 5.2.0 |
| **reference** | string                 | 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[¶](#getcollectiongroupresult "Permanent link")

| Prop          | Type                                         | Description                      | Since |
| ------------- | -------------------------------------------- | -------------------------------- | ----- |
| **snapshots** | [DocumentSnapshot](#documentsnapshot)<T>\[\] | The documents in the collection. | 5.2.0 |

#### DocumentSnapshot[¶](#documentsnapshot "Permanent link")

| Prop         | Type                                  | Description                                                                                 | Since |
| ------------ | ------------------------------------- | ------------------------------------------------------------------------------------------- | ----- |
| **id**       | string                                | The document's identifier within its collection.                                            | 5.2.0 |
| **path**     | string                                | The path of the document.                                                                   | 5.2.0 |
| **data**     | T \| null                             | An object containing the data for the document. Returns null if the document doesn't exist. | 5.2.0 |
| **metadata** | [SnapshotMetadata](#snapshotmetadata) | Metadata about the snapshot, concerning its source and if it has local modifications.       | 6.2.0 |

#### SnapshotMetadata[¶](#snapshotmetadata "Permanent link")

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

#### AddCollectionSnapshotListenerOptions[¶](#addcollectionsnapshotlisteneroptions "Permanent link")

| Prop                 | Type                                                              | Description                                                                                         | Since |
| -------------------- | ----------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | ----- |
| **reference**        | string                                                            | The reference as a string, with path components separated by a forward slash (/).                   | 5.2.0 |
| **compositeFilter**  | [QueryCompositeFilterConstraint](#querycompositefilterconstraint) | The filter to apply.                                                                                | 5.2.0 |
| **queryConstraints** | QueryNonFilterConstraint\[\]                                      | Narrow or order the set of documents to retrieve, but do not explicitly filter for document fields. | 5.2.0 |

#### GetCollectionResult[¶](#getcollectionresult "Permanent link")

| Prop          | Type                                         | Description                      | Since |
| ------------- | -------------------------------------------- | -------------------------------- | ----- |
| **snapshots** | [DocumentSnapshot](#documentsnapshot)<T>\[\] | The documents in the collection. | 5.2.0 |

#### AddDocumentSnapshotListenerOptions[¶](#adddocumentsnapshotlisteneroptions "Permanent link")

| Prop          | Type   | Description                                                                       | Since |
| ------------- | ------ | --------------------------------------------------------------------------------- | ----- |
| **reference** | string | The reference as a string, with path components separated by a forward slash (/). | 5.2.0 |

#### GetDocumentResult[¶](#getdocumentresult "Permanent link")

| Prop         | Type                                     | Description                    | Since |
| ------------ | ---------------------------------------- | ------------------------------ | ----- |
| **snapshot** | [DocumentSnapshot](#documentsnapshot)<T> | The current document contents. | 5.2.0 |

#### DeleteDocumentOptions[¶](#deletedocumentoptions "Permanent link")

| Prop          | Type   | Description                                                                       | Since |
| ------------- | ------ | --------------------------------------------------------------------------------- | ----- |
| **reference** | string | The reference as a string, with path components separated by a forward slash (/). | 5.2.0 |

#### EnablePersistenceOptions[¶](#enablepersistenceoptions "Permanent link")

| Prop                | Type    | Description                                                                      | Default            | Since |
| ------------------- | ------- | -------------------------------------------------------------------------------- | ------------------ | ----- |
| **cacheSizeBytes**  | number  | The cache size in bytes.                                                         | 104857600 (100 MB) | 8.2.0 |
| **synchronizeTabs** | boolean | Whether to synchronize persistence across multiple tabs. Only available for Web. | false              | 8.2.0 |

#### GetCollectionOptions[¶](#getcollectionoptions "Permanent link")

| Prop                 | Type                                                              | Description                                                                                         | Since |
| -------------------- | ----------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | ----- |
| **reference**        | string                                                            | The reference as a string, with path components separated by a forward slash (/).                   | 5.2.0 |
| **compositeFilter**  | [QueryCompositeFilterConstraint](#querycompositefilterconstraint) | The filter to apply.                                                                                | 5.2.0 |
| **queryConstraints** | QueryNonFilterConstraint\[\]                                      | Narrow or order the set of documents to retrieve, but do not explicitly filter for document fields. | 5.2.0 |

#### GetCollectionGroupOptions[¶](#getcollectiongroupoptions "Permanent link")

| Prop                 | Type                                                              | Description                                                                                         | Since |
| -------------------- | ----------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | ----- |
| **reference**        | string                                                            | The reference as a string, with path components separated by a forward slash (/).                   | 5.2.0 |
| **compositeFilter**  | [QueryCompositeFilterConstraint](#querycompositefilterconstraint) | The filter to apply.                                                                                | 5.2.0 |
| **queryConstraints** | QueryNonFilterConstraint\[\]                                      | Narrow or order the set of documents to retrieve, but do not explicitly filter for document fields. | 5.2.0 |

#### GetCountFromServerResult[¶](#getcountfromserverresult "Permanent link")

| Prop      | Type   | Description                                | Since |
| --------- | ------ | ------------------------------------------ | ----- |
| **count** | number | The number of documents in the collection. | 6.4.0 |

#### GetCountFromServerOptions[¶](#getcountfromserveroptions "Permanent link")

| Prop                 | Type                                                              | Description                                                                                      | Since |
| -------------------- | ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ | ----- |
| **reference**        | string                                                            | The reference as a string, with path components separated by a forward slash (/).                | 6.4.0 |
| **compositeFilter**  | [QueryCompositeFilterConstraint](#querycompositefilterconstraint) | The filter to apply.                                                                             | 8.3.0 |
| **queryConstraints** | QueryNonFilterConstraint\[\]                                      | Narrow or order the set of documents to count, but do not explicitly filter for document fields. | 8.3.0 |

#### GetDocumentOptions[¶](#getdocumentoptions "Permanent link")

| Prop          | Type   | Description                                                                       | Since |
| ------------- | ------ | --------------------------------------------------------------------------------- | ----- |
| **reference** | string | The reference as a string, with path components separated by a forward slash (/). | 5.2.0 |

#### RemoveSnapshotListenerOptions[¶](#removesnapshotlisteneroptions "Permanent link")

| Prop           | Type                      | Since |
| -------------- | ------------------------- | ----- |
| **callbackId** | [CallbackId](#callbackid) | 5.2.0 |

#### SetDocumentOptions[¶](#setdocumentoptions "Permanent link")

| Prop          | Type                          | Description                                                                       | Default | Since |
| ------------- | ----------------------------- | --------------------------------------------------------------------------------- | ------- | ----- |
| **reference** | string                        | The reference as a string, with path components separated by a forward slash (/). |         | 5.2.0 |
| **data**      | [DocumentData](#documentdata) | An object containing the data for the new document.                               |         | 5.2.0 |
| **merge**     | boolean                       | Whether to merge the provided data with an existing document.                     | false   | 5.2.0 |

#### UpdateDocumentOptions[¶](#updatedocumentoptions "Permanent link")

| Prop          | Type                          | Description                                                                       | Since |
| ------------- | ----------------------------- | --------------------------------------------------------------------------------- | ----- |
| **reference** | string                        | The reference as a string, with path components separated by a forward slash (/). | 5.2.0 |
| **data**      | [DocumentData](#documentdata) | An object containing the data for the new document.                               | 5.2.0 |

#### UseEmulatorOptions[¶](#useemulatoroptions "Permanent link")

| Prop     | Type   | Description                                                                                                                                                                     | Default | Since |
| -------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | ----- |
| **host** | string | 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** | number | The emulator port.                                                                                                                                                              | 8080    | 6.1.0 |

#### WriteBatchOptions[¶](#writebatchoptions "Permanent link")

| Prop           | Type                    | Description                             | Since |
| -------------- | ----------------------- | --------------------------------------- | ----- |
| **operations** | WriteBatchOperation\[\] | The operations to execute in the batch. | 6.1.0 |

#### WriteBatchOperation[¶](#writebatchoperation "Permanent link")

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

#### SetOptions[¶](#setoptions "Permanent link")

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

### Type Aliases[¶](#type-aliases "Permanent link")

#### QueryFilterConstraint[¶](#queryfilterconstraint "Permanent link")

`[QueryFieldFilterConstraint](#queryfieldfilterconstraint) | [QueryCompositeFilterConstraint](#querycompositefilterconstraint)`

#### QueryOperator[¶](#queryoperator "Permanent link")

`'<' | '<=' | '==' | '>=' | '>' | '!=' | 'array-contains' | 'array-contains-any' | 'in' | 'not-in'`

#### QueryNonFilterConstraint[¶](#querynonfilterconstraint "Permanent link")

`[QueryOrderByConstraint](#queryorderbyconstraint) | [QueryLimitConstraint](#querylimitconstraint) | [QueryStartAtConstraint](#querystartatconstraint) | [QueryEndAtConstraint](#queryendatconstraint)`

#### OrderByDirection[¶](#orderbydirection "Permanent link")

`'desc' | 'asc'`

#### AddCollectionGroupSnapshotListenerCallback[¶](#addcollectiongroupsnapshotlistenercallback "Permanent link")

`(event: [AddCollectionGroupSnapshotListenerCallbackEvent](#addcollectiongroupsnapshotlistenercallbackevent)<T> | null, error: any): void`

#### AddCollectionGroupSnapshotListenerCallbackEvent[¶](#addcollectiongroupsnapshotlistenercallbackevent "Permanent link")

`[GetCollectionGroupResult](#getcollectiongroupresult)<T>`

#### CallbackId[¶](#callbackid "Permanent link")

`string`

#### AddCollectionSnapshotListenerCallback[¶](#addcollectionsnapshotlistenercallback "Permanent link")

`(event: [AddCollectionSnapshotListenerCallbackEvent](#addcollectionsnapshotlistenercallbackevent)<T> | null, error: any): void`

#### AddCollectionSnapshotListenerCallbackEvent[¶](#addcollectionsnapshotlistenercallbackevent "Permanent link")

`[GetCollectionResult](#getcollectionresult)<T>`

#### AddDocumentSnapshotListenerCallback[¶](#adddocumentsnapshotlistenercallback "Permanent link")

`(event: [AddDocumentSnapshotListenerCallbackEvent](#adddocumentsnapshotlistenercallbackevent)<T> | null, error: any): void`

#### AddDocumentSnapshotListenerCallbackEvent[¶](#adddocumentsnapshotlistenercallbackevent "Permanent link")

`[GetDocumentResult](#getdocumentresult)<T>`

## FAQ[¶](#faq "Permanent link")

### How do I get notified about data changes in real time?[¶](#how-do-i-get-notified-about-data-changes-in-real-time "Permanent link")

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`?[¶](#what-is-the-difference-between-getcollection-and-getcollectiongroup "Permanent link")

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?[¶](#does-the-plugin-work-offline "Permanent link")

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 after the app is shut down or when it is first initialized.

### Can I use a Firestore database other than the default one?[¶](#can-i-use-a-firestore-database-other-than-the-default-one "Permanent link")

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.

### How do I test my app against a local Firestore instance?[¶](#how-do-i-test-my-app-against-a-local-firestore-instance "Permanent link")

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?[¶](#can-i-use-this-plugin-with-ionic-react-vue-or-angular "Permanent link")

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[¶](#related-plugins "Permanent link")

* [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[¶](#newsletter "Permanent link")

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[¶](#changelog "Permanent link")

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

## License[¶](#license "Permanent link")

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. [↩](#fnref:1 "Jump back to footnote 1 in the text")

July 8, 2026 

Back to top

```json
{"@context": "https://schema.org", "@graph": [{"@type": "TechArticle", "@id": "https://capawesome.io/docs/sdks/capacitor/firebase/cloud-firestore/#article", "headline": "Capacitor Firestore Plugin for Android, iOS & Web", "name": "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.", "inLanguage": "en", "url": "https://capawesome.io/docs/sdks/capacitor/firebase/cloud-firestore/", "mainEntityOfPage": "https://capawesome.io/docs/sdks/capacitor/firebase/cloud-firestore/", "author": {"@type": "Organization", "name": "Capawesome", "url": "https://capawesome.io", "logo": {"@type": "ImageObject", "url": "https://capawesome.io/assets/images/logo.svg"}}, "publisher": {"@type": "Organization", "name": "Capawesome", "url": "https://capawesome.io", "logo": {"@type": "ImageObject", "url": "https://capawesome.io/assets/images/logo.svg"}}, "about": {"@id": "https://capawesome.io/docs/sdks/capacitor/firebase/cloud-firestore/#software"}}, {"@type": "SoftwareSourceCode", "@id": "https://capawesome.io/docs/sdks/capacitor/firebase/cloud-firestore/#software", "name": "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.", "url": "https://capawesome.io/docs/sdks/capacitor/firebase/cloud-firestore/", "programmingLanguage": "TypeScript", "runtimePlatform": "Capacitor", "codeRepository": "https://github.com/capawesome-team", "author": {"@type": "Organization", "name": "Capawesome", "url": "https://capawesome.io", "logo": {"@type": "ImageObject", "url": "https://capawesome.io/assets/images/logo.svg"}}, "publisher": {"@type": "Organization", "name": "Capawesome", "url": "https://capawesome.io", "logo": {"@type": "ImageObject", "url": "https://capawesome.io/assets/images/logo.svg"}}}]}
{"@context": "https://schema.org", "@type": "FAQPage", "mainEntity": [{"@type": "Question", "name": "How do I get notified about data changes in real time?", "acceptedAnswer": {"@type": "Answer", "text": "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 for an example."}}, {"@type": "Question", "name": "What is the difference between getCollection and getCollectionGroup?", "acceptedAnswer": {"@type": "Answer", "text": "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."}}, {"@type": "Question", "name": "Does the plugin work offline?", "acceptedAnswer": {"@type": "Answer", "text": "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 after the app is shut down or when it is first initialized."}}, {"@type": "Question", "name": "Can I use a Firestore database other than the default one?", "acceptedAnswer": {"@type": "Answer", "text": "Yes, you can set the databaseId configuration option in your Capacitor configuration to select the Firestore database to use (see Configuration). This option is only available on Android and iOS."}}, {"@type": "Question", "name": "How do I test my app against a local Firestore instance?", "acceptedAnswer": {"@type": "Answer", "text": "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."}}, {"@type": "Question", "name": "Can I use this plugin with Ionic, React, Vue or Angular?", "acceptedAnswer": {"@type": "Answer", "text": "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."}}], "url": "https://capawesome.io/docs/sdks/capacitor/firebase/cloud-firestore/"}
```
