title: Firebase cloud function with realtime database triggers: how to update the source node?
body: <p>I am trying to write a cloud function that does the following:</p>
  
  <ol>
  <li>Listen to a new creation in 'posts/{postid}/comments/{commentsid}/' node. (This is done from database push from the frontend code). This node will have the commenter's uid under 'uid' child node.</li>
  <li>Using the uid in the child node, Look for the commenter's username, nickname, and profile picture in the 'users/uid' node and log them.</li>
  <li>Update the 'posts/{postid}/comments/{commentsid}/' node with the relevant child nodes for username, nickname, and profile picture.</li>
  </ol>
  
  <p>The code below works fine until the last part that try to do the job no. 3. The error message is 'Function returned undefined, expected Promise or value'.</p>
  
  <p>I think this is a syntax problem specific to Firebase. Could someone point me to the right syntax to use to do the task?</p>
  
  <p>Thanks a lot!</p>
  
  <pre><code> exports.commentsupdate = functions.database.ref('posts/{postid}/comments/{commentsid}/')
    .onCreate((snapshot,context) =&gt; {
       const uid=snapshot.val()['uid'];
       let username="";
       let nickname="";
       let profile_picture="";
       const ref1=database.ref('users/'+uid);
       ref1.once('value',function(ssnapshot){
          username=ssnapshot.val()['username'];
          nickname=ssnapshot.val()['nickname'];
          profile_picture=ssnapshot.val()['profile_picture'];
       }).then(()=&gt;{
          return snapshot.ref.update({
             username:username,
             nickname:nickname,
             profile_picture:profile_picture
         })
      })
  });
  </code></pre>