【问题标题】:How to get value of node in firebase database in Cloud Function如何在 Cloud Function 中获取 firebase 数据库中节点的值
【发布时间】:2017-12-06 01:24:52
【问题描述】:
exports.respublished = 
functions.database.ref('/Posts/{postid}').onWrite(event => {
  const snapshot = event.data;
  const postid = event.params.examid;
  const uid = snapshot.child('uid').val();
  const ispublic = snapshot.child('Public').val();
  firebase.database.ref('Users/' + uid).once(event => {
    const snapshot = event.data;
    const name = snapshot.child('name').val();
  });
});

该事件由另一个节点触发,我想从 firebase 数据库的另一个节点检索数据。我已经尝试了上面的代码,但它会产生一个错误,说 TypeError: firebase.database.ref(...).once is not a function。

【问题讨论】:

  • 您确定确切的错误信息吗?你的意思是firebase.database.ref().once?如果是这样,firebase 是什么?你是在别的地方定义的吗?

标签: javascript firebase firebase-realtime-database google-cloud-functions


【解决方案1】:

是的,我得到了答案,我们可以使用此代码

exports.respublished = functions.database.ref('/Posts/{postid}').onWrite(event => {
  const snapshot = event.data;
  const postid = event.params.examid;
  const uid = snapshot.child('uid').val();
  const ispublic = snapshot.child('Public').val();
  return admin.database().ref('Users/' + uid).once(event => {
    const snapshot = event.data;
    const name = snapshot.child('name').val();
  });
});

【讨论】:

    猜你喜欢
    • 2017-10-12
    • 1970-01-01
    • 2017-03-26
    • 2017-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-12
    相关资源
    最近更新 更多