是的,只需使用onCreate触发器创建三个不同的通配符函数
exports.BrandFunction = functions.firestore
.document('brands/{brandId}')
.onCreate(async (snap, context) => {
//Function doesnt need to be async unless you use await in the body
//YOUR CODE HERE
});
exports.PackFunction = functions.firestore
.document('packs/{packId}')
.onCreate(async (snap, context) => {
//YOUR CODE HERE
});
exports.ItemFunction = functions.firestore
.document('items/{itemId}')
.onCreate(async (snap, context) => {
//YOUR CODE HERE
});
请注意,您可以使用任意多个通配符来替换显式集合或文档ID,例如:
exports.BrandFunction = functions.firestore
.document('{collectionId}/{docId}')
.onCreate(async (snap, context) => {
console.log(context.params.collectionId);
console.log(context.params.docId);
return null;
});
请参阅以下文档:https://firebase.google.com/docs/functions/firestore-events#wildcards-parameters