title: Cloud Functions for Firebase write operation inside a DB event function
body: <p>I'm currently trying to learn Firebase functions.
  This new feature seems to be pretty powerful and useful.</p>
  
  <p>I'd like to use a function the catch a DB writing event, make a comparison with a specific location in DB and then write some data (depending on the comparison result) in another location in DB.</p>
  
  <p>Here's my current Node.js code:</p>
  
  <pre><code>exports.verificaFineLavoro = functions.database.ref('/Aziende/{nomeazienda}/LogAsegno/{pushidbracciante}/{pushidlog}/Asegno')
  .onWrite(event =&gt; {
    const original = event.data.val();
    console.log('VerificaFineLavoro', event.params.pushId, original);
    const aSegno = original;
    console.log('aSegno', aSegno +"");
    const FineLavoro = ref.parent.parent.parent.parent.child("Asegno/"+aSegno+"/FineLavoro");
    return event.data.ref.child('FL').set(FineLavoro);
  });
  </code></pre>
  
  <p>Currently the function gets triggered but it stops working because of the references which are probably wrong.</p>