仅检索更改的文档字段 [英] Only retrieve changed document field

查看:37
本文介绍了仅检索更改的文档字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现,聆听文档更改将总是一遍又一遍地下载完整的文档.

I found out that listening to document changes will always download the full document over and over.

在以下情况下,我对此有疑问:文档的大小接近 1 MiB (即

I have a problem with this in the following scenario: The size of a document is approaching 1 MiB (which is the limit for document size). Now, there is a number field that is the only field updating, which is just a few bytes. However, listening to this change (e.g. likes on a post) will always download the full 1 MiB of data, even though a few bytes would have been sufficient.

我知道我可以将占据大部分 1 MiB 的数据移动到单个文档的子集合中,但这不仅是 diodiomatic 而且似乎很违反直觉,但也大大增加了我的Firestore帐单,因为我需要读取 two 而不是 one 来读取文档,才能最初检索数据.

I know that I could just move the data that takes up most of the 1 MiB to a subcollection to a single document, but this would not only be unidiomatic and seem very counterintuitive, but also significantly increase my Firestore bill because I would need two instead of one document reads to retrieve the data initially.

还有其他方法可以解决此问题吗?

Is there any other way to solve this problem?

推荐答案

Firestore始终返回完整的文档.没有办法通过显式询问那些字段(类似于 SELECT FIELD1,FIELD2 语句)或隐式询问(如您所做的那样)来返回文档中字段的子集.因为只需要修改字段).

Firestore always returns complete documents. There is no way to get it to return a subset of the fields in a document, neither by explicitly asking for those fields (akin to a SELECT FIELD1, FIELD2 statement), nor implicitly asking (as you do by wanting only modified fields).

如果您要限制有效载荷较大的频繁更改文档的带宽使用,则将数据的更多静态部分放在单独的文档中的解决方法是有效的.

If you want to limit bandwidth usage for frequently changing documents with a large payload, your workaround of putting the more static part of the data in a separate document is valid.

另请参阅:

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