Per iniziare
Copia un prompt di configurazione con i passaggi di installazione e la guida markdown completa per questo plugin.
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-firebase-firestore`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/firebase-firestore/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
Puoi usare il nostro setup assistito dall'IA per installare il plugin. Aggiungi le skill Capgo al tuo strumento di IA usando il seguente comando:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsPoi usa il seguente prompt:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-firebase-firestore` plugin in my project.Se preferisci la configurazione manuale, installa il plugin eseguendo questi comandi e segui le istruzioni specifiche per piattaforma qui sotto:
bun add @capgo/capacitor-firebase-firestorenpx cap syncImporta
Sezione intitolata “Import”import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';Avvio rapido
Sezione intitolata “Quick start”import { plugin } from '@capgo/capacitor-firebase-firestore';
const result = await plugin.addDocument({ reference: 'users', data: {},});console.log(result);Esempio: addCollectionGroupSnapshotListener
Sezione intitolata “Esempio: addCollectionGroupSnapshotListener”import { plugin } from '@capgo/capacitor-firebase-firestore';
const result = await plugin.addCollectionGroupSnapshotListener({ reference: 'reference' }, (event, error) => { console.log(event);});console.log(result);Esempio: addCollectionSnapshotListener
Sezione intitolata “Esempio: addCollectionSnapshotListener”import { plugin } from '@capgo/capacitor-firebase-firestore';
const result = await plugin.addCollectionSnapshotListener({ reference: 'reference' }, (event, error) => { console.log(event);});console.log(result);Errori comuni
Sezione intitolata “Errori comuni”- Sync nativo: esegui
npx cap syncdopo gli aggiornamenti dei plugin. - Fonte di verità: fidati
src/definitions.tsnel repo GitHub.
Panoramica API
Sezione intitolata “Panoramica API”addDocument
Sezione intitolata “addDocument”Aggiunge un nuovo documento a una collezione con i dati forniti.
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.addDocument({} as AddDocumentOptions);setDocument
Sezione intitolata “setDocument”Scrive nel documento indicato dal riferimento specificato. Se il documento non esiste ancora, verrà creato.
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.setDocument({} as SetDocumentOptions);getDocument
Sezione intitolata “getDocument”Legge il documento a cui fa riferimento il riferimento specificato.
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.getDocument({} as GetDocumentOptions);updateDocument
Sezione intitolata “updateDocument”Aggiorna i campi del documento a cui fa riferimento il riferimento specificato.
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.updateDocument({} as UpdateDocumentOptions);deleteDocument
Sezione intitolata “deleteDocument”Elimina il documento indicato dal riferimento specificato.
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.deleteDocument({} as DeleteDocumentOptions);writeBatch
Sezione: “writeBatch”Esegue più operazioni di scrittura in un unico batch.
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.writeBatch({} as WriteBatchOptions);getCollection
Sezione: “getCollection”Legge la collezione indicata dal riferimento specificato.
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.getCollection({} as GetCollectionOptions);getCollectionGroup
Sezione: “getCollectionGroup”Legge il collection group indicato dal riferimento specificato.
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.getCollectionGroup({} as GetCollectionGroupOptions);getCountFromServer
Sezione: “getCountFromServer”Recupera il numero di documenti in una collezione.
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.getCountFromServer({} as GetCountFromServerOptions);clearPersistence
Sezione: “clearPersistence”Svuota lo storage persistente. Include le scritture in sospeso e i documenti in cache.
Deve essere chiamato dopo la chiusura dell'app o durante la sua prima inizializzazione.
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.clearPersistence();enableNetwork
Sezione: “enableNetwork”Riabilita l'uso della rete.
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.enableNetwork();disableNetwork
Sezione: “disableNetwork”Disabilita l'uso della rete.
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.disableNetwork();useEmulator
Sezione intitolata “useEmulator”Instrumenta la tua app per comunicare con l'emulatore Firestore.
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.useEmulator({} as UseEmulatorOptions);addDocumentSnapshotListener
Sezione intitolata “addDocumentSnapshotListener”Aggiunge un listener per gli eventi di snapshot del documento.
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.addDocumentSnapshotListener({} as AddDocumentSnapshotListenerOptions, {} as AddDocumentSnapshotListenerCallback<T>);addCollectionSnapshotListener
Sezione intitolata “addCollectionSnapshotListener”Aggiunge un listener per gli eventi di snapshot della collection.
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.addCollectionSnapshotListener({} as AddCollectionSnapshotListenerOptions, {} as AddCollectionSnapshotListenerCallback<T>);addCollectionGroupSnapshotListener
Sezione intitolata “addCollectionGroupSnapshotListener”Aggiunge un listener per gli eventi di snapshot della collection group.
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.addCollectionGroupSnapshotListener({} as AddCollectionGroupSnapshotListenerOptions, {} as AddCollectionGroupSnapshotListenerCallback<T>);removeSnapshotListener
Sezione intitolata “removeSnapshotListener”Rimuove un listener per gli eventi snapshot di documenti o collezioni.
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.removeSnapshotListener({} as RemoveSnapshotListenerOptions);Riferimento ai tipi
Sezione: “Type Reference”AddDocumentOptions
Sezione intitolata “AddDocumentOptions”export interface AddDocumentOptions { /** * The reference as a string, with path components separated by a forward slash (`/`). * * @since 5.2.0 * @example 'users' */ reference: string; /** * An object containing the data for the new document. * * @since 5.2.0 * @example { first: 'Alan', last: 'Turing', born: 1912 } */ data: DocumentData;}AddDocumentResult
Sezione intitolata “AddDocumentResult”export interface AddDocumentResult { /** * The reference of the newly added document. * * @since 5.2.0 */ reference: DocumentReference;}SetDocumentOptions
Sezione intitolata “SetDocumentOptions”export interface SetDocumentOptions { /** * The reference as a string, with path components separated by a forward slash (`/`). * * @since 5.2.0 * @example 'users/Aorq09lkt1ynbR7xhTUx' */ reference: string; /** * An object containing the data for the new document. * * @since 5.2.0 * @example { first: 'Alan', last: 'Turing', born: 1912 } */ data: DocumentData; /** * Whether to merge the provided data with an existing document. * * @since 5.2.0 * @example true * @default false */ merge?: boolean;}DocumentData
Sezione intitolata “DocumentData”export interface DocumentData { /** * A mapping between a field and its value. * * @since 5.2.0 */ [field: string]: any;}GetDocumentOptions
Sezione intitolata “GetDocumentOptions”export interface GetDocumentOptions { /** * The reference as a string, with path components separated by a forward slash (`/`). * * @since 5.2.0 */ reference: string;}GetDocumentResult
Sezione intitolata “GetDocumentResult”export interface GetDocumentResult<T> { /** * The current document contents. * * @since 5.2.0 */ snapshot: DocumentSnapshot<T>;}UpdateDocumentOptions
Sezione intitolata “UpdateDocumentOptions”export interface UpdateDocumentOptions { /** * The reference as a string, with path components separated by a forward slash (`/`). * * @since 5.2.0 */ reference: string; /** * An object containing the data for the new document. * * @since 5.2.0 * @example { first: 'Alan', last: 'Turing', born: 1912 } */ data: DocumentData;}DeleteDocumentOptions
Sezione intitolata “DeleteDocumentOptions”export interface DeleteDocumentOptions { /** * The reference as a string, with path components separated by a forward slash (`/`). * * @since 5.2.0 */ reference: string;}WriteBatchOptions
Sezione intitolata “WriteBatchOptions”export interface WriteBatchOptions { /** * The operations to execute in the batch. * * @since 6.1.0 */ operations: WriteBatchOperation[];}GetCollectionOptions
Sezione intitolata “GetCollectionOptions”export interface GetCollectionOptions { /** * The reference as a string, with path components separated by a forward slash (`/`). * * @since 5.2.0 */ reference: string; /** * The filter to apply. * * @since 5.2.0 */ compositeFilter?: QueryCompositeFilterConstraint; /** * Narrow or order the set of documents to retrieve, but do not explicitly filter for document fields. * * @since 5.2.0 */ queryConstraints?: QueryNonFilterConstraint[];}GetCollectionResult
Sezione intitolata “GetCollectionResult”export interface GetCollectionResult<T> { /** * The documents in the collection. * * @since 5.2.0 */ snapshots: DocumentSnapshot<T>[];}GetCollectionGroupOptions
Sezione intitolata “GetCollectionGroupOptions”export interface GetCollectionGroupOptions { /** * The reference as a string, with path components separated by a forward slash (`/`). * * @since 5.2.0 */ reference: string; /** * The filter to apply. * * @since 5.2.0 */ compositeFilter?: QueryCompositeFilterConstraint; /** * Narrow or order the set of documents to retrieve, but do not explicitly filter for document fields. * * @since 5.2.0 */ queryConstraints?: QueryNonFilterConstraint[];}Fonte di verità
Sezione intitolata “Fonte di verità”Questa pagina è generata dal src/definitions.ts. Riesegui la sync quando il API pubblico cambia upstream.
Continua da Getting Started
Sezione intitolata “Continua da Getting Started”Se stai usando Per iniziare per pianificare le operazioni della dashboard e di API, collegalo a Panoramica API per i dettagli di implementazione in Panoramica di API, Introduzione per i dettagli di implementazione in Introduzione, Chiavi API per i dettagli di implementazione delle chiavi API, Dispositivi per i dettagli di implementazione in Devices, e Bundle per il dettaglio di implementazione in Bundles.