2 回答

TA貢獻1866條經驗 獲得超5個贊
路徑中的任何內容都可以是通配符,因此如果要在所有集合上觸發:
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(...) {
...
}

TA貢獻1853條經驗 獲得超18個贊
添加到另一個答案,您可以使用檢查來執行通配符功能:
exports.myfunction = functions.firestore
.document('{colId}/{docId}')
.onWrite(async (change, context) => {
const col = context.params.colId;
const doc = context.params.docId;
if (col === 'users' || col === 'offices') {
return...
}
return null;
});
添加回答
舉報