如何在Firestore Cloud触发功能内更新文件

时间:2019-06-22 02:33:55

标签: firebase google-cloud-firestore

我要在创建新评论时用评论计数更新Blob文档。我想将触发器onCreate与打字稿一起使用。云存储可以做到吗?到目前为止,这是我所拥有的,但是我被困住了,因为在打字稿甚至节点上看不到太多文档。

exports.commentCreated = functions.firestore
.document('comments/{commentId}')
  .onCreate((snap: any , context: any) => {

  admin.firestore().collection("blob").doc(snap.data().blobId).get()
  .then(snapshot => { 
    //1. count comment size? <-- how?
    //2. update the blob with new comment count <-- how?

    //below code is wrong
    snapshot.update({
      "commentCount": snapshot.size
    });
  })
  .catch(error => {
      console.log('22');
      //response.status(500).send("Something went wrong!");
  });

});

0 个答案:

没有答案