Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
845 views
in Technique[技术] by (71.8m points)

firebase - What is the exact size of a Firestore document?

The docs says that the size of a document is composed of:

  1. document name size
  2. The sum of the string size of each field name
  3. The sum of the size of each field value
  4. 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");
  1. (6 + 1) + (3 + 1) + 16 = 27

The field name (the array) is called geoPoints

  1. 9 + 1 = 10

I store in that array 40,327

  1. 40,327 * 16 = 645,232

There is an additional 32 additional bytes for each document

  1. 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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...