title: Firestore Query Listener
body: <p>I listen to changes to a collection with a listener </p>
  
  <p><code>query.addSnapshotListener(new EventListener&lt;QuerySnapshot&gt;()</code> </p>
  
  <p>When I add first document, listener gets it and it works as I want it to, but then when I add the second document my listener gets this second document <strong>and</strong> the first one again, then with 3rd it records this 3rd document and the rest 2, and so on. </p>
  
  <p>Can I make it that my listener gets only latest document when it is added, not all of the documents?</p>
  
  <p>EDIT:</p>
  
  <pre><code>query = chatCollectionRef.whereEqualTo("receiverID", userID).whereEqualTo("senderID", targetID);
              registration = query.addSnapshotListener(new EventListener&lt;QuerySnapshot&gt;() {
                  @Override
                  public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException e) {
  
                      if (e != null) {
                          Log.w("ListenerError", "Listen Failed");
                          return;
                      }
  
                      for (QueryDocumentSnapshot doc : queryDocumentSnapshots) {
                          Log.d("ListenerLog", "New Document in Listener")
                          Item item= doc.toObject(Item.class);
                          itemList.add(item);
                          recyclerAdapter.notifyDataSetChanged();
                      }
                    }
                  }
  </code></pre>
  
  <p>The problem is that when first document is added my listener and recyclerview shows this <a href="https://i.stack.imgur.com/ZEzPt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZEzPt.png" alt="enter image description here"></a></p>
  
  <p>And then, when i add second document, listener gets all two of them, not only the latest one, and my recyclerView looks like this</p>
  
  <p><a href="https://i.stack.imgur.com/hKcp4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hKcp4.png" alt="enter image description here"></a></p>