title: How to paginate to previous page using AngularFire, Firestore and Firebase
body: <p>Sorry I have seen this question has been asked many times in different ways here such as: </p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/51831193/howto-paginate-back-to-previous-pages-in-a-angular6-and-firebase-firestore-set">Howto paginate back to previous pages in a Angular(6) and firebase Firestore setup</a></li>
  <li><a href="https://stackoverflow.com/questions/51830045/how-to-paginate-firestore-dataset-by-individual-page">How to paginate Firestore dataset by individual page?</a> </li>
  </ul>
  
  <p>But NONE of the answers really explain the solution or are understandable. </p>
  
  <p>Also I went though many tutorials such as: </p>
  
  <ul>
  <li><a href="https://howtofirebase.com/firebase-data-structures-pagination-96c16ffdb5ca" rel="noreferrer">https://howtofirebase.com/firebase-data-structures-pagination-96c16ffdb5ca</a> </li>
  <li><a href="https://rexrainbow.github.io/phaser3-rex-notes/docs/site/firebase-firestore/#paginate" rel="noreferrer">https://rexrainbow.github.io/phaser3-rex-notes/docs/site/firebase-firestore/#paginate</a></li>
  </ul>
  
  <p>To details: </p>
  
  <p>So here is what I have done so far </p>
  
  <pre><code>let query = ref.orderBy(orderBy, asc ? 'asc' : 'desc').limit(limit);
          if (startAfter) {
            // Thiis works as it should
            query = query.startAfter(startAfter);
          }
          if (endBefore) {
            // This here does not work or give the correct results. I get the first page. 
            query = query.endBefore(endBefore);
          }
          return query;
  </code></pre>
  
  <p>So: </p>
  
  <p><code>query = query.startAfter(startAfter);</code> works as expected. </p>
  
  <p>However: </p>
  
  <p><code>query = query.endBefore(endBefore)</code> does not end before that document I think it ends up to the limit. </p>