title: Why is my function not reaching this forEach loop?
body: <p>I am trying to add to my firestore database when a user signs up, but for some reason the code simply isn't reaching the forEach loop. I've tried adding a bunch of logging as you can see below. The logs show that it reached <code>console.log('_createUser: 1.1');</code> but it never reaches <code>console.log('_createUser: 2');</code>. Why isn't it doing the forEach loop?</p>
  <p>Note - the function finishes with status code 200.</p>
  <pre><code>import * as functions from 'firebase-functions';
  import * as admin from 'firebase-admin';
  // import { error } from 'firebase-functions/lib/logger';
  admin.initializeApp();
  
  exports.createUser = functions.https.onCall(async (data, context) =&gt; {
    console.log('_createUser: ');
    const uid = context?.auth?.uid;
    if (uid) {
      const username = data.user;
      const email = data.email;
      console.log('_createUser: 1');
      //Check to see if that username already exists
      const qData = await admin.firestore().collection('users').where('username', '==', username).limit(1).get();
      console.log('_createUser: 1.1');
      qData.forEach(doc =&gt; {
        console.log('_createUser: 2');
        const otherUsername = doc.get('username').toString();      
        if (otherUsername) {
          console.log('_createUser: Username is already in use.');
          return 'Username is already in use.'
        }
        else {
          console.log('_createUser: 3');
          //Create collection for this user's friends list
          const friendsColl = 'friends_' + uid;
          const friendsDoc = admin.firestore().collection(friendsColl).doc();
          friendsDoc.set({
            //Forces the collection to exist
            exists: 1, 
  
            //Other useful data
            createDate: admin.firestore.FieldValue.serverTimestamp(),
            modifiedDate: admin.firestore.FieldValue.serverTimestamp(),
            ownerUsername: username,
            ownerUID: uid, //
            rowType: 'B', //N = normal, B = backend (created for server side reasons)
          })
          .then(() =&gt; {
            console.log(&quot;Document successfully written!&quot;);
          })
          .catch((error) =&gt; {
            console.error(&quot;Error writing document: &quot;, error);
          });
          console.log('_createUser: 4');
          const userDoc = admin.firestore().collection('users').doc(uid); // use uid as document ID
          userDoc.set({
            createDate: admin.firestore.FieldValue.serverTimestamp(),
            modifiedDate: admin.firestore.FieldValue.serverTimestamp(),
            username: username,
            email: email,
            stat: 1, //0 = banned, 1 = normal
            uid: uid,
            friendsColl: friendsColl,
          })
          .then(() =&gt; {
            console.log(&quot;Document successfully written!&quot;);
          })
          .catch((error) =&gt; {
            console.error(&quot;Error writing document: &quot;, error);
          });
          return console.log('_createUser_finished');
        };
      });    
    }
    else {
      return console.log('_createUser_Error: User is not authorized');
    };
  });
  </code></pre>