title: Get all Firestore documents after specific date
body: <p>What I try to accomplish is the following: I have a collection where documents get added with a timestamp in them. I then want to listen to that collection via snapshotlistener, but just for new documents. So I update my timestamp to the newest document-timestamp received, and try to query only the documents newer than my timestamp. In onCreate I assign <code>lastUpdateTime</code> a date in the past, so that I get the first document added.</p>
  
  <pre><code>val sdf = SimpleDateFormat("dd/MM/yyyy", Locale.US)
      try {
          lastUpdateTime = sdf.parse("01/01/2000")
  
      } catch (e: ParseException) {
         //
      }
  </code></pre>
  
  <p>then I add the <code>snapshotlistener</code> and try to update <code>lastUpdateTime</code> in order to just look for documents newer than thist Date/Time</p>
  
  <pre><code>val path = //...path to my collection
  private var lastUpdateTime = Any() //my up-to-date timestamp. I first assign it some date in the past, to make sure it gets the first document added.
  // some code
  
  talksListener = path.whereGreaterThan("timestamp", lastUpdateTime)
                  .addSnapshotListener(EventListener&lt;QuerySnapshot&gt; { snapshot, e -&gt;
  
                      if (snapshot != null &amp;&amp; !snapshot.isEmpty &amp;&amp; !snapshot.metadata.hasPendingWrites()) {                            
  
                          for (dSnapshot in snapshot) {
                              val thisTimestamp = dSnapshot.get("timestamp")    
  
                              if (thisTimestamp != null) {
                                  lastUpdateTime = thisTimestamp
                              }  
                          }
                      }
                  })
  </code></pre>
  
  <p>But every time I add an document, I get the whole collection again.
  I also tried all combinations with <code>orderBy</code> and <code>startAt/endAt/startBefore/EndBefore</code> but the result is the same. Either I get nothing, or the whole collection every time a new document is added.
  for example:</p>
  
  <pre><code>talksListener = path.orderBy("timestamp").startAfter(lastUpdateTime)
  </code></pre>
  
  <p>Where is the problem here?
  Also, on a different note, is there a possibility to include <code>!snapshot.metadata.hasPendingWrites()</code> into the query in Kotlin. The <a href="https://firebase.google.com/docs/firestore/query-data/listen" rel="nofollow noreferrer">documentation</a> says to use <code>MetadataChanges.INCLUDE</code> but I do not get how to implement it in Kotlin. Every Hint is much appreciated.</p>
  
  <p><strong>edit 1:</strong>
  My firestore DB is structured like this:</p>
  
  <pre><code>users/{user}/messages/{message} -&gt; here is the timestamp located
  </code></pre>
  
  <p>and my path leads to <code>./messages</code></p>
  
  <p><strong>edit 2:</strong> 
  the solution is to detach and reattach the listener after the new lastUpdateTime is assigned. That does not sound good to me, so if anyone has a better solution, I am happy to hear it. For the time being I will stick to it though.</p>