Javascript Firebase的云功能“;创建;触发器-多个集合
我在根上创建了3个集合,即同一项目中的品牌、包装和项目。我是否可以同时对每个集合保留“创建”函数。是的,只需使用onCreate触发器创建三个不同的通配符函数即可Javascript Firebase的云功能“;创建;触发器-多个集合,javascript,node.js,firebase,google-cloud-functions,Javascript,Node.js,Firebase,Google Cloud Functions,我在根上创建了3个集合,即同一项目中的品牌、包装和项目。我是否可以同时对每个集合保留“创建”函数。是的,只需使用onCreate触发器创建三个不同的通配符函数即可 exports.BrandFunction = functions.firestore .document('brands/{brandId}') .onCreate(async (snap, context) => { //Function doesnt need to be async unless you use
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
});
是的,只需使用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.multiCollections = functions.firestore
.document('{collectionId}/{docId}')
.onCreate(async (snap, context) => {
console.log(context.params.collectionId);
console.log(context.params.docId);
return null;
});
请参阅文档:注意,您可以使用任意数量的通配符来替换显式集合或文档ID,例如:
exports.multiCollections = functions.firestore
.document('{collectionId}/{docId}')
.onCreate(async (snap, context) => {
console.log(context.params.collectionId);
console.log(context.params.docId);
return null;
});
查看文档:感谢雷诺·塔内克和巴贝科的快速回复,我不知怎么错过了这个。。非常感谢。感谢雷纳德·塔内克和巴贝科的快速回复,我不知怎么错过了这个。。谢谢。