代码之家  ›  专栏  ›  技术社区  ›  Elsunhoty

firebase firestore cloud函数从不执行

  •  -2
  • Elsunhoty  · 技术社区  · 8 年前

    我让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

    2 回复  |  直到 8 年前
        1
  •  3
  •   Peter Haddad    8 年前

    更改此:

    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
  •  0
  •   Sheikh Hasib    8 年前

    FireBase SDK之前(<=v0.9.1) 版本 event.params.id 工作了。但是 现在(v1.0.0) Android提供文档以供使用 context.params.id .

    使用 context event 你的问题会解决的。

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