Problem:
I'm building an app where I want to display a list of 50k locations. Knowing that the size of geographical point is 16 bytes, I decided to store all of them in a single document.
The location where I store this list is:
db.collection("points").document("geo");
I know that the size of a document is composed of three components:
- document name size
- The sum of the string size of each field name
- The sum of the size of each field value
- 32 additional bytes
So in my case, I have:
- (6 + 1) + (3 + 1) + 16 = 27
- 9 + 1 = 10 as the name of the field is
geoPoints
- 50,000 * 16 = 800,000
- 32 additional bytes
So in my case the total is 800,069 bytes which less than 1,048,576 bytes as it is mentioned in the docs. If I try to add this list to the above document, I get:
INVALID_ARGUMENT: A document cannot be written because it exceeds the maximum size allowed.
However, I'm not able to add less than that. I made some tests and I could only write a number of 40,327
GeoPoints, meaning:
- (6 + 1) + (3 + 1) + 16 = 27
- 9 + 1 = 10 as the name of the field is
geoPoints
- 40,327 * 16 = 645,232
- 32 additional bytes
So a total of 27 + 10 + 645,232 + 32 = 645,301 bytes, which is much less than what says in the docs.
If I try to write 40,328 instead of 40,327, I get the same error.
Question:
How to store the total of 1,048,576 bytes, as it is mentioned in the docs?