现已推出具有 MongoDB 兼容性的 Firestore 企业版!
了解详情。
計費示例
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
僅適用於 Cloud Firestore Enterprise 版。
|
本頁面提供範例,說明在一些常見情境中,如何計算帳單單位。請注意,根據查詢計畫、資料形狀和可用索引等因素,每個查詢處理的資料可能有所不同。
建議使用「查詢說明」功能,進一步瞭解特定查詢的成本和效能。
讀取作業
大多數讀取作業都涉及對特定文件執行點讀取,或根據 ID 掃描一系列資料。讀取作業會消耗讀取單位。讀取單位是以 4 KiB 為一組計算。請參閱以下範例。
Point reads
點讀的計費範例如下:
- 讀取單一 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 個位元組的費用。
- 計算集合中的文件數量。查詢會掃描集合中的 1000 個項目。消耗: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 的文件,該文件在集合中具有 1 個索引。消耗:2 個寫入單位
- 刪除 1 KiB 的文件,該文件在集合中沒有索引。消耗:1 個寫入單位
索引建構
索引建構作業會針對建構期間建立或修改的索引項目收費。只要新增或移除索引定義,就會產生這些費用。索引項目的計費方式與寫入作業相同,每 1 KiB 會產生 1 個寫入單位。
- 為含有 500 份文件的集合建立新索引,每個索引項目為 1 KiB。耗用 500 個寫入單位。
- 刪除含有 500 份文件的集合的現有索引,每個刪除的索引項目為 1 KiB。耗用 500 個寫入單位。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-29 (世界標準時間)。
[null,null,["上次更新時間: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."]]