小编mic*_*i07的帖子

Firebase 函数:更新集合中的所有文档

我正在尝试为 Firebase 编写一个函数,用于在更新另一种类型的文档时更新特定集合中的所有文档。

functions.firestore.document('/accounts/{accountId}/resources/{resourceId}')
  .onUpdate((change, context) => {
    const resource = context.params.resourceId;
    admin.firestore().collection('/accounts/'+account+'/tasks')
      .where('resourceId', '=', resource).get().then(snapshot => {
        snapshot.forEach(doc => {
          doc.update({
            fieldA: 'valueA',
            fieldB: 'valueB'
          });
        });
        return true;
    })
    .catch(error => {
      console.log(error);
    });
});
Run Code Online (Sandbox Code Playgroud)

这不起作用,但我不知道该怎么做,这是我第一次为 Firebase 制作函数。

javascript firebase google-cloud-functions google-cloud-firestore

5
推荐指数
1
解决办法
4292
查看次数