javascript - 多个集合的云函数触发器
问题描述
exports.myFunction = functions.firestore
.document('users/{userID}')
.onDelete((snap, context) => {
// do something
});
我希望这个函数也能触发另一个集合,比如offices
. 在不复制和粘贴整个内容的情况下执行此操作的最佳方法是什么?
解决方案
路径中的任何内容都可以是通配符,因此如果要在所有集合上触发:
exports.myFunction = functions.firestore
.document('{collectionName}/{userID}')
.onDelete((snap, context) => {
// do something
});
但是,无法设置触发两个但不是所有集合的单个路径。如果您愿意,只需通过在 aa(常规非云)函数中隔离该代码来最小化代码重复:
exports.myFunction = functions.firestore
.document('users/{userID}')
.onDelete((snap, context) => {
doSomething(...)
});
exports.myFunction = functions.firestore
.document('offices/{officeID}')
.onDelete((snap, context) => {
doSomething(...)
});
function doSomething(...) {
...
}
推荐阅读
- parameters - 如何在不训练 Gensim Doc2Vec 中的文档的情况下更改已保存模型的参数?
- arduino - 使按钮中断运行循环/功能
- javascript - 如何在 Google 电子表格的 Google Apps 脚本中解析 JSON
- compare - 如何删除 Shopify 中的添加到比较按钮(PORTO 主题)
- php - HTML Template PHP get Header() - 如何获取其内容?
- c++ - 从枚举编译时间函数?
- reactjs - Typescript 和 React:使用解构的事件处理程序的正确类型是什么?
- python - 根据关键字有条件地 grep 和连接 CSV 中的行
- java - 1 引用没有可用的子 com.google.firebase.database.DatabaseException:无法将 java.lang.String 类型的对象转换为类型
- arrays - 从结构指针的排序数组构建二叉搜索树