The docs says that the size of a document is composed of:
- 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
The following document example:
- "type": "Personal"
- "done": false
- "priority": 1
- "description": "Learn Cloud Firestore"
Has the size of 147
.
Question:
When calculating the size of a document, is there anything else I should care of? Perhaps some metadata? Because when using this calculation, there's for sure something missing.
I have this class:
class Points {
public List<GeoPoint> geoPoints;
public Points() {}
public Points(List<GeoPoint> geoPoints) {
this.geoPoints = geoPoints;
}
}
And this is how I create the list and how I write it to the database:
List<GeoPoint> geoPoints = new ArrayList<>();
for (int i = 1; i <= 40_327 ; i++) {
geoPoints.add(new GeoPoint(11.22, 33.44));
}
DocumentReference geoRef = db.collection("pointsgeo");
geoRef.set(new Points(geoPoints)).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Log.d("TAG", "geoPoints added successfully");
} else {
Log.d("TAG", task.getException().getMessage());
}
}
});
Edit with example:
My reference is:
db.collection("points").document("geo");
- (6 + 1) + (3 + 1) + 16 = 27
The field name (the array) is called geoPoints
- 9 + 1 = 10
I store in that array 40,327
- 40,327 * 16 = 645,232
There is an additional 32 additional bytes for each document
- 32
So it makes a total of:
Total: 27 + 10 + 645,232 + 32 = 645,301 bytes
There is nowhere specified in the docs that each element in the array counts more than his length:
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
Even so, if I need to add a byte (bytes) for every position, for example, 1 for a one digit number, 2 for a two digit number and so on and an additional 1 byte as it is in case of Strings, I should add 230,850
to the total.
So it makes a new total of 645,301 + 230,850 = 876,153?.
This is the maximum allowed. Adding 40,328, will be rejected.
Anyway it is again less than the maximum 1,048,576
allowed.
See Question&Answers more detail:
os