title: Error Database Triggered Cloud function with Promise
body: <p>I am trying to write a firebase cloud function that essentially does 2 things for now:</p>
  
  <p>1) gets triggered whenever a user comes online/offline</p>
  
  <p>2) fetch all the conversations for this user.</p>
  
  <p>The below code is able to perform Step 1, but returns Function returned undefined, expected Promise or value Error in the console.</p>
  
  <p>I am not sure how to write Promises and this is my first Firebase function. Please assist.</p>
  
  <pre><code>    exports.offlineHandler = functions.database.ref('/users/{userid}/status')
        .onUpdate((change, context) =&gt; {
          const status = change.after.val();
          const userId = context.params.userid;
          console.log('the user is now ', status, "with mobile no ", userId);
          // fetch a users conversations list
          if (status === "offline") {
            console.log("offline exec start");
            return fetchUserConversations(userId)
              .then(results =&gt; {
                console.log("offline exec end");
                for (result in results) {
                  console.log("id is", result);
                }
                return results;
              }).catch(err =&gt; {
                console.error("An error has occurred.", err);
                return err;
              });
          } else {
            console.log("user came online");
          }
          return null;
        });
  
  function fetchUserConversations(userId) {
    return admin.firestore().collection('users/${userId}/conversations').get()
      .then(snapshot =&gt; {
        var conversations = [];
        snapshot.forEach(doc =&gt; {
          console.log("This is conversation id =&gt; ", doc.id);
          conversations.concat(doc.id);
        });
        return conversations;
        //return conversations;
      }).catch(err =&gt; {
        console.error(err);
        return err;
      });
  }
  </code></pre>