Community生产力与协作github.com

firebase/firebase-firestore-enterprise-native-mode

Firestore 企业级原生模式的综合指南,涵盖配置、数据模型、安全规则及 SDK 使用。当用户需要设置 Firestore Enterprise 原生模式、编写安全规则或在应用中使用 Firestore SDK 时,使用此技能。

firebase-firestore-enterprise-native-mode 是什么?

本技能(firebase/firestore-enterprise-native-mode)为开发者提供使用 Firebase Firestore 企业级原生模式的完整指导。它涵盖了从初始配置(包括项目启用和数据库设置)到数据建模(如集合、文档与索引设计)、安全规则编写(基于角色的访问控制和数据验证)以及客户端 SDK 集成(Web、Android、iOS 等)的方方面面。该技能基于 Firestore Enterprise 的官方文档,适合需要生产环境级可靠性、强一致性或跨区域分布式的用户。支持的平台包括所有 Firebase 支持的环境,并强调最佳实践(如事务处理、离线支持和性能优化)。通过执行实际代码示例和规则模板,该技能可帮助开发者避免常见陷阱,并确保数据安全与可扩展性。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/firebase/agent-skills/tree/main/skills/firebase-firestore-enterprise-native-mode

Installed? Explore more 生产力与协作 skills: steipete/gemini, steipete/gh-issues, steipete/skill-creator · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

firebase-firestore-enterprise-native-mode 是做什么的?

适用于 Firestore 企业级原生模式的综合指南,包括配置、数据模型、安全规则及 SDK 使用。当用户需要帮助设置 Firestore Enterprise 原生模式、编写安全规则或在应用中使用 Firestore SDK 时,请使用此技能。

概述

Firestore 企业级原生模式是 Firebase 提供的一种高性能、可扩展的 NoSQL 文档数据库解决方案。它专为需要强一致性、低延迟和全球分布的生产环境应用而设计。

功能特性

  • 自动多区域复制:数据自动跨多个地理位置复制,实现高可用性。
  • 强一致性:所有读取操作在提交后立即反映最新数据。
  • 实时监听:通过 SDK 内置的实时监听功能,客户端可立即接收数据变更。
  • 灵活的查询:支持复合查询、排序、过滤和聚合。
  • 精细的安全规则:通过基于角色的访问控制和数据验证,保护数据安全。

快速入门

  1. 启用 Firestore API:在 Google Cloud Console 中启用 Firestore API。
  2. 创建数据库:选择原生模式并配置区域设置。
  3. 设置安全规则:定义基础规则以保护数据。
  4. 初始化 SDK:在应用中初始化 Firebase SDK。

数据模型

Firestore 使用文档和集合来组织数据:

  • 文档:包含键值对(字段)的单位。
  • 集合:文档的容器。
  • 子集合:文档内部的嵌套集合。

示例:

users/{userId}/posts/{postId}

安全规则

安全规则使用类似 JavaScript 的语法,控制数据读写权限。基本结构:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if request.auth != null;
    }
  }
}

SDK 使用

支持多种平台的 SDK:

  • Web:使用 firebase 模块。
  • Android:使用 com.google.firebase:firebase-firestore。
  • iOS:使用 FirebaseFirestore 框架。

示例(Web):

import { initializeApp } from "firebase/app";
import { getFirestore, doc, getDoc } from "firebase/firestore";

const app = initializeApp(firebaseConfig);
const db = getFirestore(app);

const docSnap = await getDoc(doc(db, "users", "alice"));

最佳实践

  • 使用批量写入:批量操作可减少 API 调用次数。
  • 避免深度嵌套:保持文档浅层以优化查询性能。
  • 合理设置索引:针对频繁查询的字段创建复合索引。
  • 实施离线支持:启用离线持久化以提升用户体验。

故障排除

常见问题及解决方案:

  • 权限不足:检查安全规则是否允许操作。
  • 查询超时:确保已为查询创建适当索引。
  • 数据不一致:检查写入操作是否成功提交。

相关资源

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

firebase/developing-genkit-dart

Generates code and provides documentation for the Genkit Dart SDK. Use when the user asks to build AI agents in Dart, use Genkit flows, or integrate LLMs into Dart/Flutter applications.

firebase/developing-genkit-go

Develop AI-powered applications using Genkit in Go. Use when the user asks to build AI features, agents, flows, or tools in Go using Genkit, or when working with Genkit Go code involving generation, prompts, streaming, tool calling, or model providers.

firebase/developing-genkit-js

Develop AI-powered applications using Genkit in Node.js/TypeScript. Use when the user asks about Genkit, AI agents, flows, or tools in JavaScript/TypeScript, or when encountering Genkit errors, validation issues, type errors, or API problems.

firebase/developing-genkit-python

Develop AI-powered applications using Genkit in Python. Use when the user asks about Genkit, AI agents, flows, or tools in Python, or when encountering Genkit errors, import issues, or API problems.

firebase/firebase-ai-logic

Official skill for integrating Firebase AI Logic (Gemini API) into web applications. Covers setup, multimodal inference, structured output, and security.

firebase/firebase-ai-logic-basics

Official skill for integrating Firebase AI Logic (Gemini API) into web applications. Covers setup, multimodal inference, structured output, and security.

firebase/firebase-app-hosting-basics

Deploy and manage web apps with Firebase App Hosting. Use this skill when deploying Next.js/Angular apps with backends.

firebase/firebase-auth-basics

Guide for setting up and using Firebase Authentication. Use this skill when the user's app requires user sign-in, user management, or secure data access using auth rules.

firebase/firebase-basics

Provides foundational setup, authentication, and project management workflows for Firebase using the Firebase CLI. Use when checking Firebase CLI version (must use 'npx -y firebase-tools@latest --version'), initializing a Firebase environment, authenticating, setting active projects, or setting up `google-services.json` or `GoogleService-Info.plist` files.

firebase/firebase-crashlytics

Comprehensive guide for Firebase Crashlytics, including provisioning and SDK usage. Use this skill when the user needs help setting up Crashlytics, adding crash reporting, or using the Crashlytics SDK in their application.

firebase/firebase-data-connect

Builds and deploys Firebase SQL Connect (aka Firebase Data Connect) backends with PostgreSQL securely. Use when designing schemas with tables and relations, writing authorized queries and mutations, configuring real-time data updates, or generating type-safe SDKs. Use when you need a relational database with Firebase, or when the user mentions SQL Connect or Data Connect.

firebase/firebase-firestore

Sets up, manages, and executes queries against Cloud Firestore database instances, including advanced native full-text search and relational joins using pipelines. You MUST unconditionally activate this skill if you plan to use Firestore in any way. Use when listing or creating Firestore databases, configuring security rules, designing data models, writing client SDK queries (including search/joins), or checking indexes.

firebase/firebase-firestore-basics

Comprehensive guide for Firestore basics including provisioning, security rules, and SDK usage. Use this skill when the user needs help setting up Firestore, writing security rules, or using the Firestore SDK in their application.

firebase/firebase-firestore-standard

Comprehensive guide for Firestore Standard Edition, including provisioning, security rules, and SDK usage. Use this skill when the user needs help setting up Firestore, writing security rules, or using the Firestore SDK in their application.

firebase/firebase-hosting-basics

Skill for working with Firebase Hosting (Classic). Use this when you want to deploy static web apps, Single Page Apps (SPAs), or simple microservices. Do NOT use for Firebase App Hosting.

firebase/firebase-local-env-setup

Bare minimum INITIAL setup for getting started with Firebase (Node.js, CLI installation, first-time login). Use ONLY for first-time setup. For updating, troubleshooting, or refreshing an existing environment, use the firebase-basics skill instead.

firebase/firebase-remote-config-basics

Comprehensive guide for Firebase Remote Config, including template management and SDK usage. Use this skill when the user needs help setting up Remote Config, managing feature flags, or updating app behavior dynamically.

firebase/firebase-security-rules-auditor

A skill to evaluate how secure Firestore security rules are. Use this when Firestore security rules are updated to ensure that the generated rules are extremely secure and robust.

firebase/firestore-security-rules-auditor

A skill to evaluate how secure Firestore security rules are. Use this when Firestore security rules are updated to ensure that the generated rules are extremely secure and robust.

firebase/xcode-project-setup

Safely modifies Xcode projects (.pbxproj) to add Swift Packages and link files. Use this skill whenever an iOS project needs dependencies installed (e.g. Firebase, Alamofire).

相关技能