title: Get older snapshot for pagination when querying with limit(toLast:)
body: <p>Im building a chat feature for my app using Firestore. I'm using <code>limit(toLast:)</code> because I'm fetching based on the timestamp, this method gives me the latest messages saved in my DB. But it is giving me trouble when trying to fetch the snapshot/documents prior to that for loading older messages. Heres my code:</p>
  <pre><code>fileprivate func paginateFetchMessages() {
      var query: Query!
      
      if let nextStartingSnap = self.lastDocumentSnapshot {
          query = DBCall.fireRef.collection(&quot;friendMessages&quot;)
          .document(currentUID)
          .collection(friendUID)
          .order(by: &quot;timestamp&quot;).limit(toLast: 5).start(afterDocument: nextStartingSnap)
      } else {
          query = DBCall.fireRef.collection(&quot;friendMessages&quot;)
          .document(currentUID)
          .collection(friendUID)
          .order(by: &quot;timestamp&quot;).limit(toLast: 5)
      }
      
      query.addSnapshotListener { querySnapshot, error in
          guard let snapshot = querySnapshot else {
              print(&quot;Error fetching snapshots: \(error!)&quot;)
              return
          }
          
          guard let lastSnap = snapshot.documents.last else {
              self.refreshControl.endRefreshing()
              return
          }
          
          print(snapshot.documents)
          
          self.lastDocumentSnapshot = lastSnap
          
          snapshot.documentChanges.forEach({ (change) in
              
              if change.type == .added {
                 let data = change.document.data()
                  let text = data[&quot;message&quot;] as! String
                  let fromID = data[&quot;fromID&quot;] as! String
                  let messageID = data[&quot;messageId&quot;] as? String ?? &quot;&quot;
                  let isRead = data[&quot;isRead&quot;] as? Bool ?? false
                  let timestamp = data[&quot;timestamp&quot;] as! Timestamp
                  
                  let user = MessageKitUser(senderId: fromID, displayName: &quot;&quot;)
                  let message = MessageKitText(text: text, user: user, messageId: messageID, date: Date(), isRead: isRead, firDate: timestamp )
                  
                  self.insertMessage(message)
                  self.refreshControl.endRefreshing()
              }
          })
      }
  }
  </code></pre>
  <p>When I use <code>snapshot.documents.last</code> nothing returns because im fetching the &quot;last&quot; documents initially. I need to get the 5 snapshots before the last, each time when paginating.</p>
  <p>Let me know if this doesn't make sense and you have questions. Thank you!!</p>