【发布时间】:2017-09-15 10:52:00
【问题描述】:
这是我的数据库,我想在PUBLISHED_CONTENT_LIKES 的孩子上触发 onWrite 事件。当我在publishedContentId1 下添加另一个userId 时,我可以在我的云函数中使用event.params.pushId 将contentId 标识为publishedContentId1。
exports.handleLikeEvent = functions.database.ref('/USER_MANAGEMENT/PUBLISHED_CONTENT_LIKES/{pushId}')
.onWrite(event => {
// Grab the current value of what was written to the Realtime Database.
//const userId = event.data.child(publishedContentId);
//const test = event.params.val();
const publishedContentId = event.params.pushId;
var result = {"publishedContentId" : "saw"}
// You must return a Promise when performing asynchronous tasks inside a Functions such as
// writing to the Firebase Realtime Database.
// Setting an "uppercase" sibling in the Realtime Database returns a Promise.
return event.data.ref.parent.parent.child('PUBLISHED_CONTENTS/'+publishedContentId).set(result);
});
但是我也想获得新添加的userId。如何使用上述事件获取该 userId?
【问题讨论】:
标签: node.js firebase firebase-realtime-database firebase-cloud-messaging google-cloud-functions