这是我的数据库,我想在PUBLISHED_CONTENT_LIKES
的子项上触发onWrite事件。当我在publishedContentId1
下添加另一个userId时,我可以使用publishedContentId1
在我的云计算功能中将contentId标识为event.params.pushId
。
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?
答案 0 :(得分:1)
您可以在event.data
下获取正在撰写的数据。要确定新用户ID:
event.data.val().userID
我建议您观看最新的Firecast on writing Database functions,因为它涵盖了这个主题。