Firestore document does NOT have 1 MiB (1,048,576 bytes) [duplicate]

主宰稳场 提交于 2020-04-18 05:46:49

问题


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:

  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

So in my case, I have:

  1. (6 + 1) + (3 + 1) + 16 = 27
  2. 9 + 1 = 10 as the name of the field is geoPoints
  3. 50,000 * 16 = 800,000
  4. 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:

  1. (6 + 1) + (3 + 1) + 16 = 27
  2. 9 + 1 = 10 as the name of the field is geoPoints
  3. 40,327 * 16 = 645,232
  4. 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?


回答1:


The document also stores a data type for each field. You can see this in the JSON that is returned from the http api. My guess would be that these data type tags also count against the size limit.

Depending on the access rules for your database you can also see this by accessing a document directly via its url:

https://firestore.googleapis.com/v1/projects/PROJECT_NAME/databases/(default)/documents/COLLECTION_NAME/DOCUMENT_ID

{
"name": "projects/PROJECT_NAME/databases/(default)/documents/COLLECTION_NAME/DOCUMENT_ID",
"fields": {
    "Name": {
        "stringValue": "Hobbies"
    },
    "Active": {
        "booleanValue": true
    }
},
"createTime": "2019-12-02T16:03:07.111185Z",
"updateTime": "2020-03-12T13:44:01.827176Z"

}



来源:https://stackoverflow.com/questions/61103830/firestore-document-does-not-have-1-mib-1-048-576-bytes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!