如何在Cloud Function中获取firebase数据库中的节点值

时间:2022-12-07 21:16:32
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();
  });
});

The event is triggered by another node and i want to retrive data from another node of firebase database. I have tried the above code but it produces an error saying TypeError: firebase.database.ref(...).once is not a function.

该事件由另一个节点触发,我想从firebase数据库的另一个节点中检索数据。我已经尝试了上面的代码,但它产生了一个错误,说明TypeError:firebase.database.ref(...)。一次不是一个函数。

1 个解决方案

#1


0  

yes i got the answer we can use this code

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

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();
  });
});

#1


0  

yes i got the answer we can use this code

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

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();
  });
});