我正在尝试在Firestore上使用OnDelete触发器来实现我的云功能。我有两个集合“警报”和“日志”。 Log对象有一个“alertId”键。我想要做的是删除警报以使用云功能删除所有共同记录日志。
类似的东西:
exports.deleteLogs = functions.database.instance('my-app').ref('/alerts/{alertId}')
.onDelete((snap) => {
snap.ref('logs',ref => ref.where('alertId', '==', alertId)).delete();
});
答案 0 :(得分:0)
您可以在删除Firestore文档时触发功能:
exports.deleteUser = functions.firestore
.document('alerts/{alertID}')
.onDelete((snap, context) => {
// Get an object representing the document prior to deletion
const deletedValue = snap.data();
// From there, get the deleted alert's id and delete all logs
// with that alertId key
});