# Cloud Firestore

**Cloud Firestore** 是 Google 推出的无服务器、云端托管的 NoSQL 文档数据库，通过 Firebase 和 [Google Cloud Platform](https://www.edgepedia.org/zh/google-cloud-platform) 提供，将数据存储在组织为集合的文档中，并实时同步至移动端和 Web 客户端。它于 2017 年 10 月 3 日以测试版发布，定位为面向移动端和 Web 应用开发的全托管文档数据库，提供 iOS、Android 和 Web SDK、离线数据访问、实时同步，以及具备强一致性的自动多区域数据复制。<sup>[1](https://developers.googleblog.com/introducing-cloud-firestore-our-new-document-database-for-apps/)</sup> Google 将其描述为支持自动扩缩、具备高性能且便于应用开发的企业级 NoSQL 文档数据库。<sup>[2](https://docs.cloud.google.com/datastore/docs/firestore-or-datastore?hl=en)</sup>

| 关键事实 | 详情 |
|---|---|
| 数据模型 | NoSQL、面向文档：由键值字段组成的文档存放于集合中；文档可包含子集合和嵌套对象（映射）；集合和文档在首次写入数据时隐式创建<sup>[3](https://firebase.google.com/docs/firestore/data-model)</sup> |
| 文档限制 | 文档最大 1 MiB（1,048,576 字节）；子集合最大深度 100；映射或数组中的字段最大深度 20<sup>[4](https://cloud.google.com/firestore/docs/quotas)</sup> |
| 可用性与延迟 | 多区域部署可用性 SLA 为 99.999%，区域部署为 99.99%，读取延迟为个位数毫秒<sup>[5](https://cloud.google.com/firestore/mongodb-compatibility/docs/overview)</sup> |
| 免费额度（标准版） | 1 GiB 存储数据、每日 50,000 次文档读取、每日 20,000 次写入、每日 20,000 次删除、每月 10 GiB 出站流量；每个项目恰好一个免费数据库<sup>[6](https://firebase.google.com/docs/firestore/pricing)</sup> |
| MongoDB 兼容性 | Firestore 企业版提供兼容 MongoDB 的 API，使现有 MongoDB 应用代码、驱动程序、工具和集成可直接在 Firestore 上运行<sup>[5](https://cloud.google.com/firestore/mongodb-compatibility/docs/overview)</sup> |
| 访问方式 | 适用于 Apple、Android、Web、Node.js、Java、Python、Unity、C++ 和 Go 的原生 SDK，以及 REST 和 RPC API<sup>[7](https://firebase.google.com/docs/firestore/index.html)</sup> |

## 数据模型

Firestore 将数据存储在文档中，文档即存储单元。文档是一种轻量记录，包含映射到值的字段，每个文档由集合内的名称标识。文档类似 JSON 记录，不同之处包括额外的数据类型（布尔值、数字、字符串、地理点、二进制大对象、时间戳、数组和嵌套映射）以及文档大小限制。<sup>[3](https://firebase.google.com/docs/firestore/data-model)</sup>

文档存放于集合中，集合是仅存放文档的容器，不能直接保存原始字段值或其他集合。文档可以包含子集合和嵌套对象，从而支持随数据库增长而扩展的层级数据结构。该数据库无模式：同一集合中的文档可以携带不同的字段和数据类型，不过 Google 建议使用一致的字段以便于查询。集合和文档通过赋值数据隐式创建，当最后一个文档被删除时，集合随之不复存在。<sup>[3](https://firebase.google.com/docs/firestore/data-model)</sup>

## 查询与事务

Firestore 支持带复合排序和过滤的索引查询：过滤条件可以链式叠加，单个查询可以同时对同一属性进行过滤和排序。查询是浅层的，仅返回特定集合或集合组中的文档，而不返回子集合数据，并且必须返回完整文档。查询性能与结果集大小成正比，而与数据集大小无关，因为查询默认建立索引。<sup>[8](https://firebase.google.com/docs/database/rtdb-vs-firestore?hl=en)</sup>

写入通过 set 和 update 操作以及数组和数字运算符等高级变换完成。事务可以原子性地读取和写入数据库中任意部分的数据，平台还支持原子批处理操作和强一致性保证。<sup>[7](https://firebase.google.com/docs/firestore/index.html)</sup><sup> • </sup><sup>[8](https://firebase.google.com/docs/database/rtdb-vs-firestore?hl=en)</sup>

## 版本与 MongoDB 兼容性

Firestore 提供标准版和企业版。企业版增加了兼容 MongoDB 的 API，因此现有 MongoDB 应用代码、驱动程序、工具以及 MongoDB 集成的开源生态均可与 Firestore 配合使用；查询可通过标准 MongoDB 驱动程序或 MongoDB 查询语言（MQL）发出。<sup>[5](https://cloud.google.com/firestore/mongodb-compatibility/docs/overview)</sup>

近期版本大幅扩展了企业版。2026 年 1 月，原生模式下的企业版新增了管道操作接口，这是一种支持复杂表达式和函数（如 `min`、`max`、`substring`、`regex_match` 和 `array_contains_all`）的新查询接口，索引创建变为可选。2026 年 4 月，原生模式下的企业版和管道操作正式全面可用，同时提供文本搜索和地理空间搜索、`update(...)` 和 `delete()` 的管道阶段，以及带子查询的连接。<sup>[9](https://docs.cloud.google.com/firestore/docs/release-notes)</sup>

Firestore 还为旧版 App Engine 应用维护向后兼容的 Datastore API，项目可以将单个数据库配置为 Datastore 模式兼容，但这样做将失去对 Firestore 完整功能集的访问权限。<sup>[10](https://docs.cloud.google.com/datastore/docs/concepts/overview)</sup><sup> • </sup><sup>[2](https://docs.cloud.google.com/datastore/docs/firestore-or-datastore?hl=en)</sup>

## 与 Firebase Realtime Database 的比较

Firebase 提供两个客户端可访问的 NoSQL 文档数据库，Google 建议新客户从 Cloud Firestore 开始，并称其受到超过 600,000 名开发者的信赖。<sup>[8](https://firebase.google.com/docs/database/rtdb-vs-firestore?hl=en)</sup> 两者在若干实际方面存在差异：

- **数据模型。** Firestore 将数据存储为文档集合，对于复杂的层级数据，所需的反规范化和数据扁平化较少；Realtime Database 将数据存储为一棵大型 JSON 树，在规模扩大时更难组织。<sup>[8](https://firebase.google.com/docs/database/rtdb-vs-firestore?hl=en)</sup>
- **查询。** Realtime Database 的查询可以按属性排序或过滤，但不能同时进行，且某些查询的性能会随数据集增大而下降；Firestore 的索引查询使性能与结果集大小挂钩。<sup>[8](https://firebase.google.com/docs/database/rtdb-vs-firestore?hl=en)</sup>
- **延迟与扩展。** Realtime Database 延迟极低，典型响应时间不超过 10 毫秒，但在单个数据库中可扩展到约 200,000 个并发连接和 1,000 次写入/秒，超出后需要分片。Firestore 完全自动扩展，对并发连接数或数据库整体每秒写入次数没有限制，但会限制单个文档或索引的写入速率。<sup>[8](https://firebase.google.com/docs/database/rtdb-vs-firestore?hl=en)</sup>
- **在线状态。** Realtime Database 原生记录客户端连接状态；Firestore 原生不支持在线状态，但可通过 Cloud Functions 同步两者来构建该功能。<sup>[8](https://firebase.google.com/docs/database/rtdb-vs-firestore?hl=en)</sup>
- **定价。** Firestore 主要按操作（读取、写入、删除）收费，带宽和存储按较低费率收费；Realtime Database 仅按带宽和存储收费，但费率较高。<sup>[8](https://firebase.google.com/docs/database/rtdb-vs-firestore?hl=en)</sup>

两个数据库可以在同一个 Firebase 应用或项目中使用。<sup>[8](https://firebase.google.com/docs/database/rtdb-vs-firestore?hl=en)</sup>

## 定价与配额

Firestore 根据读取、写入和删除的文档数，为满足查询而读取的索引条目数，包含元数据和索引开销的存储量，以及网络带宽计费。存储和带宽以吉比字节（GiB，1 GiB = 2<sup>30</sup> 字节）计量，费用按日累计。索引条目读取按每批最多 1,000 个索引条目计为一次读取操作收费，但 k-近邻向量搜索除外，其每批为 100 个条目。<sup>[6](https://firebase.google.com/docs/firestore/pricing)</sup>

硬性限制影响应用设计。事务最长持续 270 秒，空闲过期时间为 60 秒；单个文档在 Commit 操作或事务中最多可接受 500 次字段变换；未启用计费时数据库最多支持 200 个复合索引，启用计费后为 1,000 个；每个文档最多可有 40,000 个索引条目；大于 1,500 字节的索引字段值会被截断。<sup>[4](https://cloud.google.com/firestore/docs/quotas)</sup>

## 位置与近期平台功能

数据库可置于区域或多区域位置，Google 持续增加区域，包括 `europe-north2` 斯德哥尔摩（2025 年 3 月）和多区域 `nam7` 美国（中部和东部），后者由 `us-central1`（艾奥瓦）和 `us-east4`（[北弗吉尼亚](https://www.edgepedia.org/zh/northern-virginia)）组成（2025 年 3 月）。<sup>[9](https://docs.cloud.google.com/firestore/docs/release-notes)</sup> Firestore API 的区域和多区域端点于 2026 年 3 月正式全面可用，确保请求在与数据库相同的区域或多区域内传输、存储和处理。<sup>[9](https://docs.cloud.google.com/firestore/docs/release-notes)</sup>

近期版本也反映平台向 AI 辅助开发方向发展的趋势。专为 Firestore 设计的 [Gemini CLI](https://www.edgepedia.org/zh/gemini-cli) 扩展于 2025 年 9 月进入测试版，允许从命令行查询数据库并更新数据；Firestore 远程 MCP 服务器允许 AI 应用与存储在 Firestore 中的文档交互，已从预览版（2026 年 2 月）转为正式全面可用（2026 年 4 月）；2026 年 3 月 17 日之后，启用 Firestore 时会自动启用该服务器。<sup>[9](https://docs.cloud.google.com/firestore/docs/release-notes)</sup>

## References

1. [Introducing Cloud Firestore: Our New Document Database for Apps, Google Developers Blog (October 3, 2017)](https://developers.googleblog.com/introducing-cloud-firestore-our-new-document-database-for-apps/)
2. [Choose between Firestore APIs, Google Cloud Documentation](https://docs.cloud.google.com/datastore/docs/firestore-or-datastore?hl=en)
3. [Cloud Firestore Data model, Firebase](https://firebase.google.com/docs/firestore/data-model)
4. [Quotas and limits, Firestore in Native mode, Google Cloud Documentation](https://cloud.google.com/firestore/docs/quotas)
5. [Firestore with MongoDB compatibility overview, Google Cloud Documentation](https://cloud.google.com/firestore/mongodb-compatibility/docs/overview)
6. [Understand Cloud Firestore billing, Firebase](https://firebase.google.com/docs/firestore/pricing)
7. [Firestore documentation overview, Firebase](https://firebase.google.com/docs/firestore/index.html)
8. [Choose a Database: Cloud Firestore or Realtime Database, Firebase](https://firebase.google.com/docs/database/rtdb-vs-firestore?hl=en)
9. [Firestore release notes, Firestore in Native mode, Google Cloud Documentation](https://docs.cloud.google.com/firestore/docs/release-notes)
10. [Datastore overview, Firestore in Datastore mode, Google Cloud Documentation](https://docs.cloud.google.com/datastore/docs/concepts/overview)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Databases and data systems › Database engines and systems › Cloud-managed database services

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/cloud-firestore

English original: https://www.edgepedia.org/cloud-firestore
