首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >云修复触发器不适用于云功能

云修复触发器不适用于云功能
EN

Stack Overflow用户
提问于 2020-06-25 08:46:10
回答 1查看 1.1K关注 0票数 1

我正在尝试使用CloudFi还原触发器调用一个云函数。基本上,每当一个新文档被添加到“评论”中时,我的云功能就是对我的子集合“评论”进行完整的导出。我有大约6-7个文件在我的‘评论’子收藏。我通过控制台部署了该函数,并完成了部署。但是,每当我向我的“评论”子集合添加一个新文档时,这个函数就不会被触发。谁能告诉我有什么问题吗?

providers/cloud.firestore/eventTypes/document.write触发器类型: Cloud (Beta) 事件类型:文档路径:test_/{reviews}

编辑:--我希望我的云功能只将添加到我的消防站的新文档导出到我的GCP桶中。下面是我试图编写的函数:

代码语言:javascript
复制
const functions = require('firebase-functions');
const firestore = require('@google-cloud/firestore');
const client = new firestore.v1.FirestoreAdminClient();

const bucket = 'gs://ABC/trigger_test'
exports.newFirestoreBackup = functions.firestore
  .document('test_restaurant/{Id}/reviews/{Id}') 
  .onWrite((change, context) => {
   const databaseName = client.databasePath(
   // process.env.GCLOUD_PROJECT,
   "FS-123",
    '(default)'
  );
return client
    .exportDocuments({
      name: databaseName,
      outputUriPrefix: bucket,
      // Leave collectionIds empty to export all collections
      // or define a list of collection IDs:
      // collectionIds: ['users', 'posts']
      collectionIds: ['reviews'],
    })
    .then(responses => {
      const response = responses[0];
      console.log(`Operation Name: ${response['name']}`);
      return response;
    })
    .catch(err => {
      console.error(err);
    });
  
  
  });

控制台片段:

EN

回答 1

Stack Overflow用户

发布于 2020-06-25 12:34:18

您不共享任何代码,但如果希望“每当向reviews子集合添加新文档时”触发云函数,则应使用以下路径声明该函数:

代码语言:javascript
复制
exports.createUser = functions.firestore
    .document('test_restaurant/{restaurantId}/reviews/{reviewId}')
    .onCreate((snap, context) => {...});

您也可以使用具有相同路径的onWrite()触发器。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62571378

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档