【问题标题】:Firebase Firestore Cloud Function Never ExecuteFirebase Firestore 云功能从不执行
【发布时间】:2018-11-07 19:51:26
【问题描述】:

我让 Firestore 可以在我有这样的数据库的地方运行

'posts/{postId}/comments/{commentId}'

以及添加新评论时我在 PostId 中增加字段的功能

函数已部署,但添加新评论时从不执行

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();

exports.comment= functions.firestore
    .document('posts/{postId}/comments/{commentId}')
    .onWrite((change, context) => {

   const commentId = event.params.commentId; 
    const postId = event.params.postId;
 const docRef = admin.firestore().collection('posts').doc(postId);
 return docRef.update({numberOfComments:200});

    });

我添加了很多评论,即使执行次数为 0

【问题讨论】:

    标签: javascript android firebase google-cloud-firestore google-cloud-functions


    【解决方案1】:

    改变这个:

    const commentId = event.params.commentId; 
    const postId = event.params.postId;
    

    进入这个:

    const commentId = context.params.commentId; 
    const postId = context.params.postId;
    

    更多信息在这里:

    https://firebase.google.com/docs/functions/beta-v1-diff

    【讨论】:

      【解决方案2】:

      在 Firebase SDK ( 版本 event.params.id 工作之前。但是现在 (v1.0.0) android 提供了使用 context.params.id 的文档。

      使用context insted 或event,您的问题将得到解决。

      const commentId = event.params.commentId; 
      const postId = event.params.postId;
      

      谢谢。

      【讨论】:

        猜你喜欢
        • 2018-05-09
        • 2019-12-23
        • 2019-07-14
        • 1970-01-01
        • 2018-06-15
        • 1970-01-01
        • 2018-06-30
        • 1970-01-01
        • 2021-10-26
        相关资源
        最近更新 更多