[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-05。"],[[["\u003cp\u003eString sizes in Firestore in Datastore mode are calculated as the number of UTF-8 encoded bytes plus 1, and this applies to keys, kind names, namespace names, property names, and string property values.\u003c/p\u003e\n"],["\u003cp\u003eThe size of a key is determined by the namespace string size, the full key path string size (with integer IDs being 8 bytes each), and an additional 16 bytes.\u003c/p\u003e\n"],["\u003cp\u003eProperty size is the sum of the property name's string size and the property value's size, with different types (like Boolean, Integer, String) having different size calculations.\u003c/p\u003e\n"],["\u003cp\u003eAn entity's total size is calculated by adding the key size, the sum of all property sizes, and a constant 32 bytes.\u003c/p\u003e\n"],["\u003cp\u003eThe size of a built-in index entry includes the key size of the indexed entity, the sum of the indexed property names and values, the indexed entity kind name size, and an additional 32 bytes, whereas a composite index entry consists of the key size, the sum of indexed property values, and 32 bytes.\u003c/p\u003e\n"]]],[],null,["# Storage Size Calculations\n\nThis page describes the storage size of entities, keys, properties, and\nindex entries in Firestore in Datastore mode. You can learn about the costs of this\nstorage at [Datastore mode Pricing](/datastore/docs/pricing).\n\nString size\n-----------\n\nString sizes are calculated as the number of\n[UTF-8 encoded](https://en.wikipedia.org/wiki/UTF-8) bytes + 1.\n\nThe following are stored as strings:\n\n- Keys\n- Kind names\n- Namespace names (the default namespace has size 0)\n- Property names\n- String property values\n\nFor example:\n\n- The name of the `Task` kind uses 4 bytes + 1 byte, for a total of 5 bytes.\n- The name of the `description` property uses 11 bytes + 1 byte, for a total of 12 bytes.\n- The name of the `my_name_space` namespace uses 13 bytes + 1 byte, for a total of 14 bytes.\n\nKey size\n--------\n\nThe size of a key is the sum of\n\n- The namespace string size (if not in the default namespace)\n- The full key path string size (integer IDs are 8 bytes each)\n- 16 bytes\n\nFor a key of kind `Task` in the default namespace with a numeric ID and no\nancestor: \n\n```\nTask id:5730082031140864\n```\n\nThe key size is 5 + 8 + 16 = 29 bytes:\n\n- 5 bytes for the `Task` kind name\n- 8 bytes for the numeric ID\n- 16 bytes for a key\n\nFor a key of kind `Task` in the default namespace with a string ID and no\nancestor: \n\n```\nTask name:my_task_id\n```\n\nThe key size is 5 + 11 + 16 = 32 bytes:\n\n- 5 bytes for the `Task` kind name\n- 11 bytes for the `my_task_id` string ID\n- 16 bytes for a key\n\nFor a `Task` entity with a `TaskList` ancestor in the default namespace: \n\n```\nTaskList id:5654313976201216 \u003e Task id:5629499534213120\n```\n\nThe ancestor uses 9 + 8 = 17 bytes:\n\n- 9 bytes for the `TaskList` kind name\n- 8 bytes for the numeric ID\n\nSo the key size of a `Task` entity with a `TaskList` ancestor uses 17 + 5 + 8\n+ 16 = 46 bytes:\n\n- 17 bytes for the ancestor\n- 5 bytes for the `Task` kind name\n- 8 bytes for the numeric ID\n- 16 bytes for a key\n\nIf this entity is in the `my_name_space` namespace, the key size is 14 + 46 = 60\nbytes, because the `my_name_space` name uses 14 bytes.\n\nProperty size\n-------------\n\nThe size of a property is the sum of\n\n- The property name string size\n- The property value's size\n\nThe following shows the size of property values by type.\n\nFor example, a property named `done` with a type of Boolean would use 6 bytes:\n\n- 5 bytes for the `done` property name\n- 1 byte for the Boolean value\n\nEntity size\n-----------\n\nThe size of an entity is the sum of\n\n- The [key size](#key_size)\n- The sum of the [property sizes](#property_size)\n- 32 bytes\n\nThis example is for an entity of kind `Task` in the default namespace with a\nnumeric ID and no ancestor: \n\n```\nTask id:5730082031140864\n - \"type\": \"Personal\"\n - \"done\": false\n - \"priority\": 1\n - \"description\": \"Learn Google Cloud Datastore\"\n```\n\nThe total size of the properties is 78 bytes:\n\nSo the entity size is 29 + 78 + 32 = 139 bytes:\n\n- 29 bytes for the key\n- 78 bytes for the properties\n- 32 bytes for an entity\n\nIndex entry size\n----------------\n\nThe size of an index entry is calculated as follows for built-in and composite indexes.\n\n### Built-in indexes\n\nThe size of a built-in index entry is the sum of:\n\n- The [key size](#key_size) of the indexed entity\n- The sum of the indexed property names\n- The sum of the indexed [property values](#property-value-sizes)\n- The size of the indexed entity kind name\n- 32 bytes\n\nFor example, take an entity of kind `Task` in the default namespace with a\nnumeric ID and no ancestor: \n\n```\nTask id:5730082031140864\n - \"type\": \"Personal\"\n - \"done\": false\n - \"priority\": 1\n - \"description\": \"Learn Google Cloud Datastore\"\n```\n\nIf `done` is an indexed property, the [built-in index](/datastore/docs/concepts/indexes#built_in_indexes) entry for the single\nproperty `done` index consists of the key, the `done` property name and value,\nthe `Task` kind name, and 32 bytes for an index entry. The total size of this\nindex entry is 72 bytes:\n\n- 29 for the key\n- 6 for the `done` property name and Boolean value\n- 5 for the `Task` kind name\n- 32 for an index entry\n\nBy default, Datastore mode databases automatically predefine two single\nproperty indexes for each property of each entity kind, one in ascending order\nand one in descending order. So this entity would have an index entry of size 72\nbytes in the single property `done` index in ascending order and it would have\nan index entry of size 72 bytes in the single property `done` index in\ndescending order.\n\n### Composite indexes\n\nThe size of a composite index entry is the sum of:\n\n- The [key size](#key_size) of the indexed entity\n- The sum of the indexed [property values](#property-value-sizes)\n- 32 bytes\n\nFor example, take an entity of kind `Task` in the default namespace with a\nnumeric ID and no ancestor: \n\n```\nindexes:\n- kind: Task\n properties:\n - name: done\n direction: asc\n - name: priority\n direction: asc\n```\n\nConsider a [composite index](/datastore/docs/concepts/indexes#composite_indexes) that uses the `done` and\n`priority` properties (both ascending):\n\nThe total size of the index entry in this index is 70 bytes:\n\n- 29 for the key\n- 1 for the `done` property Boolean value\n- 8 for the `priority` property integer value\n- 32 for an index entry\n\nIf you do not want Firestore in Datastore mode to maintain an index for a property,\n[exclude the property from your indexes](/datastore/docs/concepts/indexes#unindexed_properties). Note that excluding a property\nremoves it from any composite indexes.\n\nWhat's next\n-----------\n\n- Learn about [Datastore mode Pricing](/datastore/docs/pricing).\n- Learn about [Datastore mode Indexes](/datastore/docs/concepts/indexes)."]]