title: Why successListener is called even if element is not inserted into an array in Firestore document?
body: <p>I use the following code to add userId to an array in a Cloud Firestore document:</p>
  
  <pre><code>DocumentReference reference = firebaseFirestore.collection("photos").document(photoId);
  reference.update("views", FieldValue.arrayUnion(currentUser.getUid()))
          .addOnSuccessListener(new OnSuccessListener&lt;Void&gt;()
          {
              @Override
              public void onSuccess(Void aVoid)
              {
                  reference.update("viewsCount", FieldValue.increment(1));
              }
          });
  </code></pre>
  
  <p>As you can see from the code, I want the <code>viewsCount</code> to increment only if element is added to the <code>views</code> array.</p>
  
  <p>According to this <a href="https://cloud.google.com/firestore/docs/manage-data/add-data" rel="nofollow noreferrer">Adding Data</a> document, <strong><code>arrayUnion()</code> adds elements to an array but only elements not already present</strong>, and thats exactly what I wanted. </p>
  
  <p>But, the problem is that when I add an already present element into the array, the element is not inserted, but <strong><code>addOnSuccessListener</code> is called, <code>viewsCount</code> is incremented and failureListener is never called.</strong> Is there any way to prevent this? I want the <code>viewsCount</code>to be incremented only when an element is inserted into <code>views</code> array.  </p>