【发布时间】: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