Prise en main
Copiez un prompt de configuration incluant les étapes d'installation et le guide markdown complet pour ce 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.
Installer
Section intitulée « Installation »Vous pouvez utiliser notre configuration assistée par IA pour installer le plugin. Ajoutez les skills Capgo à votre outil d'IA avec la commande suivante :
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsUtilisez ensuite le prompt suivant :
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-firebase-firestore` plugin in my project.Si vous préférez une installation manuelle, installez le plugin en exécutant les commandes suivantes et suivez les instructions spécifiques à chaque plateforme ci-dessous :
bun add @capgo/capacitor-firebase-firestorenpx cap syncImporter
Section intitulée « Import »import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';Démarrage rapide
Section intitulée « Démarrage rapide »import { plugin } from '@capgo/capacitor-firebase-firestore';
const result = await plugin.addDocument({ reference: 'users', data: {},});console.log(result);Exemple : addCollectionGroupSnapshotListener
Section intitulée « Exemple : addCollectionGroupSnapshotListener »import { plugin } from '@capgo/capacitor-firebase-firestore';
const result = await plugin.addCollectionGroupSnapshotListener({ reference: 'reference' }, (event, error) => { console.log(event);});console.log(result);Exemple : addCollectionSnapshotListener
Section intitulée « Exemple : addCollectionSnapshotListener »import { plugin } from '@capgo/capacitor-firebase-firestore';
const result = await plugin.addCollectionSnapshotListener({ reference: 'reference' }, (event, error) => { console.log(event);});console.log(result);Erreurs courantes
Section intitulée « Erreurs courantes »- Sync native : exécuter
npx cap syncaprès les mises à jour du plugin. - Source de vérité : fiez-vous
src/definitions.tsau repo GitHub.
Aperçu de API
Section intitulée « Aperçu API »addDocument
Section intitulée « addDocument »Ajoute un nouveau document à une collection avec les données spécifiées.
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.addDocument({} as AddDocumentOptions);setDocument
Section intitulée « setDocument »Écrit dans le document désigné par la référence spécifiée. Si le document n'existe pas encore, il sera créé.
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.setDocument({} as SetDocumentOptions);getDocument
Section intitulée « getDocument »Lit le document désigné par la référence spécifiée.
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.getDocument({} as GetDocumentOptions);updateDocument
Section intitulée « updateDocument »Met à jour les champs du document désigné par la référence spécifiée.
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.updateDocument({} as UpdateDocumentOptions);deleteDocument
Section intitulée « deleteDocument »Supprime le document désigné par la référence spécifiée.
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.deleteDocument({} as DeleteDocumentOptions);writeBatch
Section intitulée « writeBatch »Exécute plusieurs opérations d'écriture en un seul lot.
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.writeBatch({} as WriteBatchOptions);getCollection
Section intitulée « getCollection »Lit la collection référencée par la référence spécifiée.
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.getCollection({} as GetCollectionOptions);getCollectionGroup
Section intitulée « getCollectionGroup »Lit le groupe de collections référencé par la référence spécifiée.
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.getCollectionGroup({} as GetCollectionGroupOptions);getCountFromServer
Section intitulée « getCountFromServer »Récupère le nombre de documents dans une collection.
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.getCountFromServer({} as GetCountFromServerOptions);clearPersistence
Section intitulée « clearPersistence »Vide le stockage persistant. Cela inclut les écritures en attente et les documents mis en cache.
Doit être appelé après l'arrêt de l'application ou lors de sa première initialisation.
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.clearPersistence();enableNetwork
Section intitulée « enableNetwork »Réactive l'utilisation du réseau.
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.enableNetwork();disableNetwork
Section intitulée « disableNetwork »Désactive l'utilisation du réseau.
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.disableNetwork();useEmulator
Section intitulée « useEmulator »Configurez votre app pour communiquer avec l'émulateur Firestore.
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.useEmulator({} as UseEmulatorOptions);addDocumentSnapshotListener
Section intitulée « addDocumentSnapshotListener »Ajoute un écouteur pour les événements de snapshot de document.
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.addDocumentSnapshotListener({} as AddDocumentSnapshotListenerOptions, {} as AddDocumentSnapshotListenerCallback<T>);addCollectionSnapshotListener
Section intitulée « addCollectionSnapshotListener »Ajoute un écouteur pour les événements de snapshot de collection.
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.addCollectionSnapshotListener({} as AddCollectionSnapshotListenerOptions, {} as AddCollectionSnapshotListenerCallback<T>);addCollectionGroupSnapshotListener
Section intitulée « addCollectionGroupSnapshotListener »Ajoute un écouteur pour les événements de snapshot de collection group.
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.addCollectionGroupSnapshotListener({} as AddCollectionGroupSnapshotListenerOptions, {} as AddCollectionGroupSnapshotListenerCallback<T>);removeSnapshotListener
Section intitulée « removeSnapshotListener »Supprimez un écouteur d'événements pour les snapshots de documents ou de collections.
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.removeSnapshotListener({} as RemoveSnapshotListenerOptions);Référence de type
Section intitulée « Référence de type »AddDocumentOptions
Section intitulée « 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
Section intitulée « AddDocumentResult »export interface AddDocumentResult { /** * The reference of the newly added document. * * @since 5.2.0 */ reference: DocumentReference;}SetDocumentOptions
Section intitulée « 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
Section intitulée « DocumentData »export interface DocumentData { /** * A mapping between a field and its value. * * @since 5.2.0 */ [field: string]: any;}GetDocumentOptions
Section intitulée « GetDocumentOptions »export interface GetDocumentOptions { /** * The reference as a string, with path components separated by a forward slash (`/`). * * @since 5.2.0 */ reference: string;}GetDocumentResult
Section intitulée « GetDocumentResult »export interface GetDocumentResult<T> { /** * The current document contents. * * @since 5.2.0 */ snapshot: DocumentSnapshot<T>;}UpdateDocumentOptions
Section intitulée « 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
Section intitulée « DeleteDocumentOptions »export interface DeleteDocumentOptions { /** * The reference as a string, with path components separated by a forward slash (`/`). * * @since 5.2.0 */ reference: string;}WriteBatchOptions
Section intitulée « WriteBatchOptions »export interface WriteBatchOptions { /** * The operations to execute in the batch. * * @since 6.1.0 */ operations: WriteBatchOperation[];}GetCollectionOptions
Section intitulée « 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
Section intitulée « GetCollectionResult »export interface GetCollectionResult<T> { /** * The documents in the collection. * * @since 5.2.0 */ snapshots: DocumentSnapshot<T>[];}GetCollectionGroupOptions
Section intitulée « 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[];}Source de vérité
Section intitulée « Source de vérité »Cette page est générée à partir de src/definitions.ts. Relancez la synchronisation lorsque l’API public change en amont.
Continuer depuis Getting Started
Section intitulée « Continuer après Prise en main »Si vous utilisez Prise en main pour planifier les opérations du dashboard et de API, connectez-l’avec Aperçu de API pour les détails d'implémentation dans « Vue d'ensemble de API », Introduction pour les détails d'implémentation dans l'introduction, Clés API pour les détails d'implémentation dans API Keys, Appareils pour les détails d'implémentation dans Devices, et Les bundles pour les détails d'implémentation dans Bundles.