Mai*_*awn 3 google-cloud-functions google-cloud-firestore
我正在尝试对 Firestore 上的 Cloud Functions 使用 OnDelete 触发器。我有两个集合“警报”和“日志”。Log 对象有一个“alertId”键。我想做的是,当删除警报时,使用云功能删除所有对应的日志。
像这样的东西:
exports.deleteLogs = functions.database.instance('my-app').ref('/alerts/{alertId}')
.onDelete((snap) => {
snap.ref('logs',ref => ref.where('alertId', '==', alertId)).delete();
});
Run Code Online (Sandbox Code Playgroud)
您可以在删除 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
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2699 次 |
| 最近记录: |