[英]do you need to create a separate collection/document for reading an aggregated document with firebase cloud function
I want to use cloud function to produce an aggregated document containing all the data i need for the first page of my app.我想使用云 function 生成一个聚合文档,其中包含我的应用程序首页所需的所有数据。 The aggregated document will be updated each time a document is add/updated in a Firestore collection A. In order to do so, I have to create a separate collection B containing a single document(the aggregated doc from cloud function) which the app will fetch from when it start right?
每次在 Firestore 集合 A 中添加/更新文档时,聚合文档都会更新。为此,我必须创建一个单独的集合 B,其中包含一个文档(来自云函数的聚合文档),应用程序将从什么时候开始获取? Hence, my cloud function will be updating the single document in Collection B?
因此,我的云 function 将更新 Collection B 中的单个文档? Am I correct in my understanding of how using cloud function to aggregate data works?
我对使用云 function 聚合数据的工作方式的理解是否正确? Thank you very much
非常感谢
This is indeed a totally valid approach.这确实是一种完全有效的方法。 Note that you may use a Transaction , in the Cloud Function, if there is a risk that source data is updated by several users in parallel.
请注意,如果存在源数据被多个用户并行更新的风险,您可以在云 Function 中使用事务。
You don't give any detail on what is in collection A (identical docs or different docs?) and what is aggregated (numbers, headlines,...), but you should try to avoid reading all the docs from collection A each time the Cloud Function is triggered.您没有详细说明集合 A 中的内容(相同的文档还是不同的文档?)以及汇总的内容(数字,标题,......),但您应该尽量避免每次都阅读集合 A 中的所有文档Cloud Function 被触发。 This may generate some unnecessary extra cost.
这可能会产生一些不必要的额外费用。 If the first page of your app aggregates some figures, you may use some counters .
如果您的应用程序的第一页汇总了一些数字,您可能会使用一些 计数器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.