Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/444.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Firebase的云功能“;创建;触发器-多个集合_Javascript_Node.js_Firebase_Google Cloud Functions - Fatal编程技术网

Javascript Firebase的云功能“;创建;触发器-多个集合

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

我在根上创建了3个集合,即同一项目中的品牌、包装和项目。我是否可以同时对每个集合保留“创建”函数。

是的,只需使用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 
});

是的,只需使用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;

    });


查看文档:

感谢雷诺·塔内克和巴贝科的快速回复,我不知怎么错过了这个。。非常感谢。感谢雷纳德·塔内克和巴贝科的快速回复,我不知怎么错过了这个。。谢谢。