How to get value of node in firebase database in Cloud Function

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.

1 answer

  • answered 2017-12-06 02:16 Paramjeet Singh

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