title: Count the total number of pendingDocumentWrites in a Firestore Collection
body: <p>I would like to get the count of documents in a collection with pendingwrites. For unsent messages counter.</p>
  <p>I did this but, every time I add a new message the count gets set back to one.</p>
  <pre class="lang-java prettyprint-override"><code>listener = firestore.collection(&quot;Chats&quot;).orderBy(&quot;timestamp&quot;, Query.Direction.DESCENDING).addSnapshotListener((value, error) -&gt; {
  
      int count = 0;
  
      for(DocumentChange change : value.getDocumentChanges){
  
          if(!change.getDocument().getMetadata().hasPendingWrites()
              // Do some stuff
          } else {
              count ++;
          }
  
      }
      setCounter(count);
  
  }
  </code></pre>