简体   繁体   English

您是否需要创建一个单独的集合/文档来读取带有 firebase 云 function 的聚合文档

[英]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.

相关问题 Firebase 云 Function 计划创建文档 - Firebase Cloud Function schedule to create document Firebase Cloud Firestore:在集合中为每个 UID 创建一个新文档 - Firebase Cloud Firestore: Creating a new document in a collection for every UID 如何从也有集合的 firebase 文档创建 Object? - How do I create an Object from a firebase document that also has a collection? firebase 中的收款文档 ID - Collection Document Id in firebase firebase 的谷歌云函数中的“获取”函数是否每次都读取每个文档? - Are "get" functions in Google cloud functions for firebase reading each document everytime? Function 在 firebase 中创建新的用户认证,但不会在用户集合中创建相应的文档 - Function creates new user authentication in firebase but won't create a corresponding document in User collection Firebase 创建文档并递增 - Firebase create a document and increment Firestore接管一分钟搞定里面的文档 Firebase Cloud Function - Firestore take over a minute to get a document inside Firebase Cloud Function 如何使用模块 Web SDK 的版本 9 在 Cloud Firestore 集合中的文档中获取文档和嵌套集合? - How do I get document and nested collection in a document in a Cloud Firestore collection using Version 9 of the Modular Web SDK? 在 firebase 上获取父集合和子集合文档 - Get parent collection & sub collection document on firebase
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM