title: Firestore transactions conditional update?
body: <p>I'm trying to check to see if a value saved in the database matches the user selection, if it does then update it otherwise don't do anything.</p>
  
  <p>I've tried the following, but get an exception:</p>
  
  <blockquote>
    <p>Caused by: com.google.firebase.firestore.FirebaseFirestoreException: Every document read in a transaction must also be written.</p>
  </blockquote>
  
  <p>Here's my code:</p>
  
  <pre><code>//update toolbar titles if they match
  final DocumentReference adminDocRef = mDbase.collection("admins").document(adminID);
  mDbase.runTransaction(new Transaction.Function&lt;Void&gt;() {
      @Override
      public Void apply(@NonNull Transaction transaction) throws FirebaseFirestoreException {
          DocumentSnapshot adminSnapshot = transaction.get(adminDocRef);
          String toolbarTitle = adminSnapshot.getString("displayedUser");
          if (userName.equals(toolbarTitle)) {
              transaction.update(adminDocRef, "displayedUser", userName);
          }
          // Success
          return null;
      }
  })
          .addOnSuccessListener(new OnSuccessListener&lt;Void&gt;() {
      @Override
      public void onSuccess(Void aVoid) {
          Log.d(TAG, "Transaction success!");
      }
  })
          .addOnFailureListener(new OnFailureListener() {
              @Override
              public void onFailure(@NonNull Exception e) {
                  Log.w(TAG, "Transaction failure.", e);
              }
          });  
  </code></pre>
  
  <p>Are transactions capable of being conditional?  If not how would you solve this problem?  Seems silly to have to do a separate get then nest an update inside of it.</p>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p>Thanks!</p>