2 回答

TA貢獻(xiàn)1866條經(jīng)驗 獲得超5個贊
路徑中的任何內(nèi)容都可以是通配符,因此如果要在所有集合上觸發(fā):
exports.myFunction = functions.firestore
.document('{collectionName}/{userID}')
.onDelete((snap, context) => {
// do something
});
但是,無法設(shè)置在兩個但并非所有集合上觸發(fā)的單個路徑。如果需要,只需通過在 aa(常規(guī)非云)函數(shù)中隔離該代碼來最小化代碼重復(fù):
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貢獻(xiàn)1853條經(jīng)驗 獲得超18個贊
添加到另一個答案,您可以使用檢查來執(zhí)行通配符功能:
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;
});
添加回答
舉報