Firebase Firestore云功能永不执行

时间:2018-05-29 08:22:25

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

我让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 个答案:

答案 0 :(得分:3)

改变这个:

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

答案 1 :(得分:0)

在使用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;

感谢。

相关问题