Firebase function error: .once is not a function

I'm trying to deploy a simple Firebase feature, but I'm having some difficulty. Every time I try to use .once on the link Firebase tells me it is not a function. Here is my code

exports.testFunction = functions.database.ref('/Rooms/{firstID}/{pushId}/On').onWrite(event => {
  const value = event.data.val();
  var ref = functions.database.ref(roomNum);
  return ref.once('value').then(snapshot => {
    console.log(snapshot.numChildren);
    return true;
  }); });

      

I've also tried the following:

firebaseRef.once('value', function(dataSnapshot) {
  console.log(snapshot.numChildren);
});

      

Nothing seems to work. Does anyone know of a fix or other way to get the number of children from a ref / snapshot?

Thank.

+3


source to share


1 answer


functions.database.ref

is a different object than the one you used to use on the client. The sole purpose - to listen to the recording, using it only function onWrite

.

You can get your requested reflector via a parameter event

.

var ref = event.data.ref

This is a link to the path you specified in onWrite

.



If you need a root link:

var rootRef = event.data.ref.root

Further reading: https://firebase.google.com/docs/reference/functions/functions.database

+5


source







All Articles