现已推出具有 MongoDB 兼容性的 Firestore 企业版!
了解详情。
价格示例
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
仅与 Cloud Firestore 企业版相关。
|
本页包含一些最常见场景中结算单位的计算示例。请注意,每项查询处理的数据量可能会因查询计划、数据形状和可用索引等因素而异。
建议使用查询说明功能,以便更好地了解特定查询的费用和性能。
读取操作次数
大多数读取操作都涉及对特定文档执行点读取,或根据标识符扫描一系列数据。读取操作会消耗读取单位。读取单位以 4 KiB 为单位计算。请参阅以下示例。
点读取
点读取的结算示例:
- 单个 1 KiB 文档的点读取。消耗:1 个读取单位
- 单个 4 KiB 文档的点读取。消耗:1 个读取单位
- 读取单个 1 MiB 文档的点读取。消耗:256 个读取单位
- 读取 100 个文档(每个文档 1 KiB)。消耗:100 个读取单位
扫描
以下示例包含扫描文档或索引条目的场景。
扫描文档
- 扫描 100 个文档(每个文档 1 KiB)的查询。消耗:25 个读取单位
扫描索引
无论扫描的是文档还是索引,扫描费用(以字节为单位)都是相同的。不过,索引条目的大小通常较小。因此,它们通常可以提供更具成本效益的数据扫描方式。
- 扫描 100 个索引条目的查询,每个条目的大小为 1 KiB。消耗:25 个读取单位。
- 扫描 100 个索引条目(每个条目 128 字节)的查询。消耗:4 个读取单位。
文档或索引条目的大小下限
在某些情况下,可能不需要读取文档或索引条目的内容即可满足查询要求。这包括简单的计数查询,例如统计集合中的文档总数。在这些情况下,每次扫描的商品至少需要 32 字节的费用。
- 统计集合中的文档数量。该查询会扫描集合中的 1,000 个商品。消耗:8 个读取单位。
扫描和点读取的组合
许多查询会结合使用扫描和点读取来满足操作需求。
- 扫描 128 个索引条目(每个 256 字节)并对 128 个文档(每个 4 KiB)执行点读取的查询。消耗:136 个读取单位,包括:
- 128 个读取单位(用于点读取)
- 索引扫描的读取单位数为 8
查询解释
查询解释可帮助您了解数据库如何执行查询。所提供的详细信息可帮助您优化查询。
使用查询解释功能时,会产生以下费用:
- 执行查询的查询解释:会产生查询费用。
- 使用“仅规划”选项的查询解释。消耗:1 个读取单位(查询的最低费用)
写入操作次数
写入操作(创建、更新和删除)的费用取决于操作期间创建、修改或删除的文档和索引的大小。写入操作会消耗写入单位。写入单位以 1 KiB 为单位分批计算。
简单的写入操作(例如按文档 ID 进行更新)只会产生写入费用。需要查询才能满足的写入操作还会产生与查询相关的读取费用。
请参阅以下示例。
创建
- 创建一个不含索引的新 10 KiB 文档。消耗:10 个写入单位
- 在集合上创建一个 1 KiB 文档,其中包含 1 个 256 字节的索引条目。消耗:2 个写入单位
更新
- 按文档 ID 查找 10 KiB 文档,并更新集合中没有索引的文档。消耗:10 个写入单位
- 按文档 ID 查找 1 KiB 文档,并更新 1 个包含 1 个索引条目(256 字节)的字段。消耗:3 个写入单位。注意:在这种情况下更新索引条目会消耗 2 个写入单位,一个用于删除,一个用于重新创建索引条目。
- 按文档 ID 查找 1 KiB 文档,但不更新任何内容(无更改)。消耗:1 个写入单位(最低写入费用)
- 查询集合中的所有 1 KiB 文档(扫描 1, 000 个文档),并在集合中插入一个没有索引的新 256 字节字段:1,000 个读取单位和 1, 000 个写入单位。
删除
- 删除一个 1 KiB 的文档,该文档在集合中有一个索引。消耗:2 个写入单位
- 删除一个 1 KiB 的文档,该文档在集合中没有索引。消耗:1 个写入单位
索引 build
索引构建会针对在构建操作期间创建或修改的索引条目收取费用。无论何时添加或移除索引定义,都会产生这些费用。索引条目的费用与写入操作相同,每 1KiB 需支付 1 个写入单位。
- 为包含 500 个文档的集合创建一个新索引,创建的索引条目每个为 1 KiB。消耗 500 个写入单位。
- 删除包含 500 个文档的集合的现有索引,删除的索引条目均为 1KiB。消耗 500 个写入单位。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-29。
[null,null,["最后更新时间 (UTC):2025-08-29。"],[],[],null,["\u003cbr /\u003e\n\n\n|--------------------------------------------------------|\n| *Relevant to Cloud Firestore Enterprise edition only.* |\n\n\u003cbr /\u003e\n\nThis page includes examples of how billing units are calculated in\nsome of the most common scenarios. Note that each query might differ in data\nprocessed based on factors such as the query plan, the shape of the data,\nand the indexes available.\n\nWe recommend using the [Query Explain](/docs/firestore/enterprise/query-explain) feature to better\nunderstand the cost and performance of your specific queries.\n\nRead operations\n\nMost read operations entail either performing a point read of a specific\ndocument or scanning a rage of data based on an identifier.\nRead operations consume read units. Read units are calculated in 4 KiB tranches. See the following examples.\n\nPoint reads\n\nExample billing for point reads:\n\n- Point read of a single 1 KiB document. Consumes: 1 read unit\n- Point read of a single 4 KiB document. Consumes: 1 read unit\n- Point read of a single 1 MiB document. Consumes: 256 read units\n- Point read of 100 documents, 1 KiB each. Consumes: 100 read units\n\nScanning\n\nThe following examples include scenarios that scan documents or index entries.\n\nScanning Documents\n\n- Query which scans 100 documents, 1 KiB each. Consumes: 25 read units\n\nScanning indexes\n\nThe scanning cost, in terms of bytes, is the same regardless of whether it is a\ndocument or index being scanned. However, index entries are often smaller\nin size. As a result, they can often provide a more cost effective way of scanning data.\n\n- Query which scans 100 index entries, 1 KiB each. Consumes: 25 read units.\n- Query which scans 100 index entries, 128 bytes each. Consumes: 4 read units.\n\nMinimum document or index entry size\n\nIn certain situations it may not be necessary to read the contents of a\ndocument or index entry to satisfy a query. This includes simple count queries\nlike counting the total number of documents in a collection.\nIn these situations, a minimum cost of 32 bytes applies per item scanned.\n\n- Count the number of documents in a collection. The query scans 1000 items in the collection. Consumes: 8 read units.\n\nCombination of scanning and point reads\n\nMany queries perform a combination of scanning and point reads to satisfy an\noperation.\n\n- Query which scans 128 index entries, 256 bytes each and performs a point read of 128 documents, 4 KiB each. Consumes: 136 read units, comprised of:\n - 128 read units for point reads\n - 8 read units for index scans\n\nQuery Explain\n\n[Query Explain](/docs/firestore/enterprise/query-explain) helps you understand how the database\nexecutes your queries. The details provided can help you optimize your\nqueries.\n\nThe following costs apply when using Query Explain:\n\n- Query Explain which executes the query: Query cost applies.\n- Query Explain using plan only option. Consumes: 1 read unit (minimum cost of a query)\n\nWrite operations\n\nWrite operations (creates, updates and deletes) are charged based on the\nsize of the documents and indexes being created, modified, or deleted during the\noperation. Write operations consume write units. Write units are calculated in 1\nKiB tranches.\n\nSimple write operations, like update by document ID, only incur the cost of the writes.\nWrite operations which require querying to satisfy the operation will\nadditionally incur the read costs associated with the query.\n\nSee the following examples.\n\nCreates\n\n- Create a new 10 KiB document with no indexes. Consumes: 10 write units\n- Create a 1 KiB document with 1 index entry of 256 bytes on the collection. Consumes: 2 write units\n\nUpdates\n\n- Find a 10 KiB document by document ID and update with no indexes on the collection. Consumes: 10 write units\n- Find a 1 KiB document by document ID and update 1 field with 1 index entry of 256 bytes. Consumes: 3 write units. Note: Updating an index entry in this situation consumes 2 write units -- one to delete and one to recreate the index entry.\n- Find a 1 KiB document by document ID and update nothing (no changes). Consumes: 1 write units (the minimum write costs)\n- Query all 1 KiB documents in a collection, which scans 1,000 documents, and insert a new 256 bytes field with no indexes on the collection: 1000 read units and 1000 writes units.\n\nDeletes\n\n- Delete a 1 KiB document, which has 1 index on the collection. Consumes: 2 write units\n- Delete a 1 KiB document, which has no indexes on the collection. Consumes: 1 write unit\n\nIndex builds\n\nIndex builds charge for the index entries created or modified during the build\noperation. These costs are incurred anytime an index definition is added or\nremoved. The index entries are billed identically to writes incurring 1 write\nunit per 1KiB.\n\n- Create a new index for a collection containing 500 documents, index entries created are 1 KiB each. Consumes 500 write units.\n- Delete an existing index for a collection containing 500 documents, index entries deleted are 1KiB each. Consumes 500 write units."]]