title: A simple cloud function to write to database
body: <p>I am attempting to write my first cloud function. Here is the function that I have deployed.</p>
  
  <pre><code>import * as functions from 'firebase-functions';
  import * as admin from 'firebase-admin';
  
  exports.onMsgAdded = functions.database.ref('/users/{uid}/messages/{to_uid}/{msg}').onCreate((snap, context) =&gt;{
      const data = snap.val();
      const msgRoot = admin.database().ref('/users/' + context.params.to_uid + '/messages/' + context.params.uid);
      return msgRoot.set(data);
  });
  </code></pre>
  
  <p>The problem is this does absolutely nothing. It is being triggered as I can see it in the functions dashboard, but the write is not being executed.</p>
  
  <p>Here I only have one user in the database. When a message is created, I want to copy it to the to_uid's user 'messages' node.</p>
  
  <p><a href="https://i.stack.imgur.com/FLmWW.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FLmWW.jpg" alt="enter image description here"></a></p>