Storage size calculations

This page describes the storage size of documents, document names, fields, and index entries in Cloud Firestore.

You can learn about the costs of this storage at Cloud Firestore Pricing.

String size

String sizes are calculated as the number of UTF-8 encoded bytes + 1.

The following are stored as strings:

  • Collection IDs
  • String document IDs
  • Document names
  • Field names
  • String field values

For example:

  • The collection ID tasks uses 5 bytes + 1 byte, for a total of 6 bytes.
  • The field name description uses 11 bytes + 1 byte, for a total of 12 bytes.

Document ID size

The size of a document ID is either the string size for a string ID or 8 bytes for an integer ID.

Document name size

The size of a document name is the sum of:

  • The size of each collection ID and document ID in the path to the document
  • 16 additional bytes

For a document in the subcollection users/jeff/tasks with a string document ID of my_task_id, the document name size is 6 + 5 + 6 + 11 + 16 = 44 bytes:

  • 6 bytes for the users collection ID
  • 5 bytes for the jeff document ID
  • 6 bytes for the tasks collection ID
  • 11 bytes for the my_task_id document ID
  • 16 additional bytes

Field value size

The following table shows the size of field values by type.

Type Size
Array The sum of the sizes of its values
Boolean 1 byte
Bytes Byte length
Date and time 8 bytes
Floating-point number 8 bytes
Geographical point 16 bytes
Integer 8 bytes
Map The size of the map, calculated the same way as document size
Null 1 byte
Reference The document name size
Text string Number of UTF-8 encoded bytes + 1

For example, a boolean field named done would use 6 bytes:

  • 5 bytes for the done field name
  • 1 byte for the boolean value

Document size

The size of a document is the sum of:

This example is for a document in subcollection users/jeff/tasks with a string document ID of my_task_id:

 - "type": "Personal"
 - "done": false
 - "priority": 1
 - "description": "Learn Cloud Firestore"

The total size of the fields is 70 bytes:

Field name and value Field size in bytes
"type": "Personal" 14
5 for the field name + 9 for the field's string value
"done": false 6
5 for the field name + 1 for the field's boolean value
"priority": 1 17
9 for the field name + 8 for the field's integer value
"description": "Learn Cloud Firestore" 33
12 for the field name + 21 for the field's string value

So the document size is 44 + 70 + 32 = 146 bytes:

  • 44 bytes for the document name
  • 70 bytes for the fields
  • 32 additional bytes

Index entry size

Index entry sizes are calculated as follows for single-field and composite indexes.

Single-field index entry size

The size of a single-field index entry is the sum of:

For example, take the document in the sub-collection users/jeff/tasks with a string document ID of my_task_id:

 - "type": "Personal"
 - "done": false
 - "priority": 1
 - "description": "Learn Cloud Firestore"

If done is an indexed field, the size of the automatic index entry for the single field done index is 109 bytes and consists of the following:

  • 44 bytes for the document name users/jeff/tasks/my_task_id
  • 27 bytes for the parent document's document name users/jeff
  • 5 bytes for the done field name
  • 1 byte for the boolean field value
  • 32 additional bytes

By default, Cloud Firestore automatically defines two single-field indexes for each field of each document, one in ascending order and one in descending order. So this document would have a 109-byte index entry in the single-field done index in ascending order, and it would have a 109-byte index entry in the single-field done index in descending order.

Composite index entry size

The size of a composite index entry is the sum of:

For example, take the document in the sub-collection users/jeff/tasks with a string document ID of my_task_id:

 - "type": "Personal"
 - "done": false
 - "priority": 1
 - "description": "Learn Cloud Firestore"

Consider a composite index that uses the done and priority fields (both ascending). The total size of the index entry in this index is 85 bytes:

  • 44 bytes for the document name users/jeff/tasks/my_task_id
  • 1 byte for the boolean field value
  • 8 bytes for the integer field value
  • 32 additional bytes

What's next

Learn about Cloud Firestore pricing.

Оставить отзыв о...

Текущей странице
Нужна помощь? Обратитесь в службу поддержки.