我让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
答案 0 :(得分:3)
改变这个:
const commentId = event.params.commentId;
const postId = event.params.postId;
进入这个:
const commentId = context.params.commentId;
const postId = context.params.postId;
更多信息:
答案 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;
感谢。