Firestore文件没有1 MiB(1,048,576字节) [英] Firestore document does NOT have 1 MiB (1,048,576 bytes)

查看:44
本文介绍了Firestore文件没有1 MiB(1,048,576字节)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:

我正在构建一个要显示5万个位置列表的应用程序.知道地理位置的大小为16个字节,我决定存储所有它们放在一个文档中.

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. 文档名称大小
  2. 每个字段名称的字符串大小之和
  3. 每个字段值的大小之和
  4. 另外32个字节

因此,我有:

  1. (6 +1)+(3 +1)+ 16 = 27
  2. 9 +1 = 10,因为该字段的名称是 geoPoints
  3. 50,000 * 16 = 800,000
  4. 另外32个字节

因此,在我的情况下,总数为800,069字节,少于,少于

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:无法写文档,因为它超出了允许的最大大小.

INVALID_ARGUMENT: A document cannot be written because it exceeds the maximum size allowed.

但是,我添加的数量不能少于此数量.我进行了一些测试,我只能写一些 40,327 GeoPoints,这意味着:

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,因为该字段的名称是 geoPoints
  3. 40,327 * 16 = 645232
  4. 另外32个字节

总共27 + 10 + 645232 + 32 = 645,301 个字节,比文档中所说的要少得多.

So a total of 27 + 10 + 645,232 + 32 = 645,301 bytes, which is much less than what says in the docs.

如果我尝试写40328而不是40327,则会出现相同的错误.

If I try to write 40,328 instead of 40,327, I get the same error.

问题:

如何存储文档中提到的1,048,576字节?

How to store the total of 1,048,576 bytes, as it is mentioned in the docs?

推荐答案

文档还为每个字段存储一种数据类型.您可以在http api返回的JSON中看到此内容.我的猜测是这些数据类型标记也计入大小限制.

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.

根据数据库的访问规则,您还可以通过直接通过其URL访问文档来查看此信息:

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/(默认)/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"

}

这篇关于Firestore文件没有1 MiB(1,048,576字节)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆