开始获取
复制一个包含安装步骤和完整 Markdown 指南的配置提示。
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.
bun add @capgo/capacitor-firebase-firestorebunx cap syncimport { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';API 介绍
Section titled “API 介绍”addDocument
Section titled “添加文档”添加一个集合中的新文档,使用给定的数据。
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.addDocument({} as AddDocumentOptions);setDocument
Section titled “设置文档”根据指定的引用写入文档。 如果文档尚未存在,则会创建。
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.setDocument({} as SetDocumentOptions);getDocument
标题:getDocument根据指定的引用读取文档。
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.getDocument({} as GetDocumentOptions);updateDocument
标题:updateDocument更新文档中指定的字段。
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.updateDocument({} as UpdateDocumentOptions);deleteDocument
标题:deleteDocument根据指定的引用删除文档。
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.deleteDocument({} as DeleteDocumentOptions);writeBatch
标题:writeBatch批量执行多个写操作.
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.writeBatch({} as WriteBatchOptions);getCollection
标题:getCollection读取指定引用指向的集合。
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.getCollection({} as GetCollectionOptions);getCollectionGroup
标题:getCollectionGroup读取指定引用指向的集合组。
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.getCollectionGroup({} as GetCollectionGroupOptions);getCountFromServer
标题:getCountFromServer从服务器获取集合中的文档数量。
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.getCountFromServer({} as GetCountFromServerOptions);clearPersistence
标题:clearPersistence清除持久存储。这包括待写入的数据和缓存的文档。
必须在应用程序关闭或应用程序首次启动后调用。
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.clearPersistence();enableNetwork
标题为“enableNetwork”重新启用网络使用。
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.enableNetwork();disableNetwork
标题为“disableNetwork”禁用网络使用。
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.disableNetwork();useEmulator
标题为“useEmulator”将应用程序配置为与Firestore模拟器通信。
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.useEmulator({} as UseEmulatorOptions);addDocumentSnapshotListener
添加文档快照监听器添加文档快照事件监听器
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.addDocumentSnapshotListener({} as AddDocumentSnapshotListenerOptions, {} as AddDocumentSnapshotListenerCallback<T>);addCollectionSnapshotListener
添加集合快照监听器添加集合快照事件监听器
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.addCollectionSnapshotListener({} as AddCollectionSnapshotListenerOptions, {} as AddCollectionSnapshotListenerCallback<T>);addCollectionGroupSnapshotListener
添加集合组快照监听器添加集合组快照事件监听器
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.addCollectionGroupSnapshotListener({} as AddCollectionGroupSnapshotListenerOptions, {} as AddCollectionGroupSnapshotListenerCallback<T>);removeSnapshotListener
移除快照监听器移除文档或集合快照事件监听器
import { FirebaseFirestore } from '@capgo/capacitor-firebase-firestore';
await FirebaseFirestore.removeSnapshotListener({} as RemoveSnapshotListenerOptions);类型参考
类型参考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
添加文档结果export interface AddDocumentResult { /** * The reference of the newly added document. * * @since 5.2.0 */ reference: DocumentReference;}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
文档数据export interface DocumentData { /** * A mapping between a field and its value. * * @since 5.2.0 */ [field: string]: any;}GetDocumentOptions
获取文档选项export interface GetDocumentOptions { /** * The reference as a string, with path components separated by a forward slash (`/`). * * @since 5.2.0 */ reference: string;}GetDocumentResult
获取文档结果export interface GetDocumentResult<T> { /** * The current document contents. * * @since 5.2.0 */ snapshot: DocumentSnapshot<T>;}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
删除文档选项export interface DeleteDocumentOptions { /** * The reference as a string, with path components separated by a forward slash (`/`). * * @since 5.2.0 */ reference: string;}WriteBatchOptions
写入批处理选项export interface WriteBatchOptions { /** * The operations to execute in the batch. * * @since 6.1.0 */ operations: WriteBatchOperation[];}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
获取集合结果export interface GetCollectionResult<T> { /** * The documents in the collection. * * @since 5.2.0 */ snapshots: DocumentSnapshot<T>[];}GetCollectionGroupOptions
Section titled “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[];}真实数据来源
Section titled “真实数据来源”本页面由插件生成 src/definitions.ts. 当公共 API 上游更改时,请重新运行同步。
从 Getting Started 继续
Section titled “从 Getting Started 继续”如果您正在使用 Getting Started 来规划仪表板和 API 操作,请将其与 API Overview 为API概述中的实现细节, 简介 为简介中的实现细节, API密钥 为API密钥中的实现细节, 设备 为设备中的实现细节,和 捆绑包 为捆绑包中的实现细节。