title: Updating collection(s) in Firebase that are created w/Cloud Functions
body: <p><strong>Be advised, the following scenario uses Cloud Firestore</strong>. </p>
  
  <p>Within my Cloud Functions <code>index.js</code>, I have a function, <code>createUserAccount</code>, that adds a newly created user to a <code>users</code> collection and sets fields for their email, photo, favorites (this is a feature in the application that does not need to be elaborated on), and some other distinct fields for a user. The function is triggered upon successful completion of the the following code snippet: </p>
  
  <pre><code>// The following method has been simplified to focus on the problem statement
  public void createAccountWithEmailAndPassword(String username, String displayName,
                                                String someOtherImportantThing) {
  
      mFirebaseAuth.createUserWithEmailAndPassword(email, password)
                   .addOnCompleteListener(getActivity(), task -&gt; {
                       if (task.isSuccessful()) {
                          Log.d(TAG, "createUserWithEmail:Success");
                          onSuccess.updateAccount(displayName, username);
                          updateUsernameProperty(username);
                          onBackPressed();
                      } else {
                            if (task.getException() != null) {
                                if (task.getException()
                                        .getMessage()
                                        .contains(EMAIL_EXISTS_ERROR)) {
                                    // Handle Email Exists Error
                                }
                            }
                            Log.w(TAG, "createUserWithEmail:failure",
                                      task.getException());
                      }
                  });
       }
  </code></pre>
  
  <p>As you can see, when the task is completed successfully a few methods are called: <code>updateUsernameProperty(String username)</code> and <code>updateAccount(String displayName, username)</code></p>
  
  <p><code>updateAccount(String displayName)</code> takes a users chosen displayName and adds this as a field to the users account. <strong>This does not make changes to the users collection - only to the authenticated account</strong>.</p>
  
  <p><code>updateUsernameProperty(String username)</code> takes the users chosen userName and <strong>sets this property as a field within the users document</strong>. Here is the code sample, as it may prove helpful to understanding my problem:</p>
  
  <pre><code>private void updateUsernameProperty(String username) {
      DocumentReference docRef = mFirestore
                                    .collection(TABLE_USERS)
                                    .document(mFirebaseAuth.getUid());
  
      docRef.update(USERNAME_KEY, username)
              .addOnSuccessListener(aVoid -&gt; Log.d(TAG, "Username DocumentSnapshot Successful"))
              .addOnFailureListener(e -&gt; Log.e(TAG, "Error Updating Document: user/uid/username", e));
  }
  </code></pre>
  
  <p>(<em>A typical path to the collection is "users/{userId}/username"</em>)</p>
  
  <p><strong>The Problem</strong>: When attempting to update the username field within a users document, the Cloud Function <code>createUserAccount</code> has not finished creating/adding the new user document to the database (i.e. An asynchronous issue).</p>
  
  <p>I've considered using rxJava2 to help alleviate this issue, but I can't seem to wrap my head around how to do this. Any help is greatly appreciated. </p>
  
  <p>If there's something you need clarification on, I'll try my best to provide the needed information.</p>