Langsung ke konten

Panduan Memulai

GitHub

Anda bisa menggunakan AI-Assisted Setup kami untuk menginstal plugin ini. Tambahkan skill Capgo ke tool AI Anda dengan command berikut:

Jendela terminal
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

Lalu gunakan prompt berikut:

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

Jika Anda lebih memilih Manual Setup, instal plugin dengan menjalankan perintah berikut dan ikuti petunjuk khusus platform di bawah ini:

Jendela terminal
bun add @capgo/capacitor-firebase-firestore
npx cap sync
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
import { plugin } from '@capgo/capacitor-firebase-firestore';
const result = await plugin.addDocument({
reference: 'users',
data: {},
});
console.log(result);
import { plugin } from '@capgo/capacitor-firebase-firestore';
const result = await plugin.addCollectionGroupSnapshotListener({ reference: 'reference' }, (event, error) => {
console.log(event);
});
console.log(result);
import { plugin } from '@capgo/capacitor-firebase-firestore';
const result = await plugin.addCollectionSnapshotListener({ reference: 'reference' }, (event, error) => {
console.log(event);
});
console.log(result);
  • Sinkronisasi Native: jalankan npx cap sync setelah upgrade plugin.
  • Sumber kebenaran tunggal: percayai src/definitions.ts di repo GitHub.

Menambahkan dokumen baru ke dalam koleksi dengan data yang diberikan.

import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.addDocument({} as AddDocumentOptions);

Menulis ke dokumen yang dirujuk oleh referensi yang ditentukan. Jika dokumen belum ada, dokumen akan dibuat.

import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.setDocument({} as SetDocumentOptions);

Membaca dokumen yang dirujuk oleh referensi yang ditentukan.

import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.getDocument({} as GetDocumentOptions);

Memperbarui field pada dokumen yang dirujuk oleh referensi yang ditentukan.

import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.updateDocument({} as UpdateDocumentOptions);

Menghapus dokumen yang dirujuk oleh referensi yang ditentukan.

import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.deleteDocument({} as DeleteDocumentOptions);

Eksekusi beberapa operasi write dalam satu batch tunggal.

import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.writeBatch({} as WriteBatchOptions);

Membaca collection yang dirujuk oleh reference tertentu.

import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.getCollection({} as GetCollectionOptions);

Membaca collection group yang dirujuk oleh reference tertentu.

import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.getCollectionGroup({} as GetCollectionGroupOptions);

Mengambil jumlah dokumen dalam sebuah collection.

import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.getCountFromServer({} as GetCountFromServerOptions);

Menghapus persistent storage. Ini mencakup pending writes dan dokumen yang di-cache.

Harus dipanggil setelah aplikasi ditutup atau saat aplikasi pertama kali diinisialisasi.

import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.clearPersistence();

Mengaktifkan kembali penggunaan jaringan.

import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.enableNetwork();

Menonaktifkan penggunaan jaringan.

import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.disableNetwork();

Instrument aplikasi Anda untuk terhubung ke emulator Firestore.

import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.useEmulator({} as UseEmulatorOptions);

Menambahkan listener untuk event document snapshot.

import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.addDocumentSnapshotListener({} as AddDocumentSnapshotListenerOptions, {} as AddDocumentSnapshotListenerCallback<T>);

Menambahkan listener untuk event collection snapshot.

import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.addCollectionSnapshotListener({} as AddCollectionSnapshotListenerOptions, {} as AddCollectionSnapshotListenerCallback<T>);

Menambahkan listener untuk event collection group snapshot.

import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.addCollectionGroupSnapshotListener({} as AddCollectionGroupSnapshotListenerOptions, {} as AddCollectionGroupSnapshotListenerCallback<T>);

Hapus listener untuk event snapshot dokumen atau koleksi.

import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.removeSnapshotListener({} as RemoveSnapshotListenerOptions);
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;
}
export interface AddDocumentResult {
/**
* The reference of the newly added document.
*
* @since 5.2.0
*/
reference: DocumentReference;
}
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;
}
export interface DocumentData {
/**
* A mapping between a field and its value.
*
* @since 5.2.0
*/
[field: string]: any;
}
export interface GetDocumentOptions {
/**
* The reference as a string, with path components separated by a forward slash (`/`).
*
* @since 5.2.0
*/
reference: string;
}
export interface GetDocumentResult<T> {
/**
* The current document contents.
*
* @since 5.2.0
*/
snapshot: DocumentSnapshot<T>;
}
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;
}
export interface DeleteDocumentOptions {
/**
* The reference as a string, with path components separated by a forward slash (`/`).
*
* @since 5.2.0
*/
reference: string;
}
export interface WriteBatchOptions {
/**
* The operations to execute in the batch.
*
* @since 6.1.0
*/
operations: WriteBatchOperation[];
}
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[];
}
export interface GetCollectionResult<T> {
/**
* The documents in the collection.
*
* @since 5.2.0
*/
snapshots: DocumentSnapshot<T>[];
}
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[];
}

Halaman ini dibuat dari plugin src/definitions.ts. Jalankan ulang sync saat API publik berubah di upstream.

Jika Anda menggunakan Panduan Memulai untuk merencanakan operasi dashboard dan API, hubungkan dengan Ringkasan API untuk detail implementasi di API Overview, Pendahuluan untuk detail implementasi di Introduction, Kunci API untuk detail implementasi di API Keys, Perangkat untuk detail implementasi di Devices, dan Bundle untuk detail implementasi di Bundles.