【问题标题】:Firestore function to track new writes of documents and limit the count of all documentsFirestore 功能可跟踪文档的新写入并限制所有文档的计数
【发布时间】:2023-04-01 13:35:01
【问题描述】:

当使用 Firestore 数据库和 Firestore 函数时,我试图实现一种方法来限制特定集合的文档计数(例如,我不希望集合包含超过 MAX_COUNT 个文档)。

这是我想要实现的模板(index.js 中的 Javascript 脚本):

exports.docAdded = functions.firestore.document('myCollection/{docID}').onWrite((change, context) => {
 if (!change.before.exists) {
     // New document Created - check total number of documents in myCollection
       //- Delete old documents in case of size>MAX_COUNT
 }
});

感谢任何帮助!

【问题讨论】:

    标签: node.js firebase google-cloud-firestore google-cloud-functions


    【解决方案1】:

    目前还没有开发出支持跟踪集合中文档数量的功能。但是,您可以尝试一些替代方案和方法,以帮助您实现您想要的限制目标。

    我建议您查看以下来自社区的文章和帖子,它们可能会对您有所帮助并提供一些关于如何实现这一目标的想法。

    如果这些信息对您有帮助,请告诉我!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-12
      • 1970-01-01
      • 2018-04-24
      • 2020-11-10
      • 2019-08-07
      • 2021-06-09
      • 2017-02-13
      • 2018-10-08
      相关资源
      最近更新 更多