【发布时间】:2019-01-31 19:54:55
【问题描述】:
我是 js 和 Firebase 云功能的新手。我在 Firebase 中有一个基本数据结构,每个“posts”和“cmets”都有一个父节点,基本上如下所示:
'posts' > userId > postId
'cmets' > postId > commentId
我有一种方法可以在有新评论时进行观察,该评论为我提供了 postId 和 commentId。该方法如下所示:
exports.observeComment = functions.database.ref('/comments/{postId}/{commentId}').onCreate((snapshot, context) => {
var postId = context.params.postId;
var commentId = context.params.commentId;
console.log('LOGGER --- New comment, postId: ' + postId + ' , commentId: ' + commentId);
return admin.database().ref().child('/posts/').once('value', function(snapshot) {
//Get userId
})
})
我现在想检索 postId 的 userId - 我该怎么做呢?
非常感谢!
【问题讨论】:
标签: javascript firebase cloud