title: Documents fetched are replacing the previous loaded documents in tableview
body: <p>I am using the below code to fetch the data from the firestore database in swift iOS. But when I scroll the new data loaded is replacing the previously loaded data in the tableview. I am trying to fix this issue but as of now no good.</p>
  
  <p>The outcome required is that adding new documents to the previously list of documents in the tableview </p>
  
  <p>Below is the code I am implementing. If any more information is required please let me know</p>
  
  <p>CODE </p>
  
  <pre><code>fileprivate func observeQuery() {
          fetchMoreIngredients = true
  
          //guard let query = query else { return }
          var query1 = query
          stopObserving()
          if posts.isEmpty{
              query1 = Firestore.firestore().collection("posts").order(by: "timestamp", descending: true).limit(to: 5)
          }
          else {
              query1 = Firestore.firestore().collection("posts").order(by: "timestamp", descending: true).start(afterDocument: lastDocumentSnapshot).limit(to: 2)
              //  query = db.collection("rides").order(by: "price").start(afterDocument: lastDocumentSnapshot).limit(to: 4)
              print("Next 4 rides loaded")
              print("hello")
          }
          // Display data from Firestore, part one
  
          listener = query1!.addSnapshotListener { [unowned self] (snapshot, error) in
              guard let snapshot = snapshot else {
                  print("Error fetching snapshot results: \(error!)")
                  return
              }
              let models = snapshot.documents.map { (document) -&gt; Post in
                  if let model = Post(dictionary: document.data()) {
                      return model
                  } else {
                      // Don't use fatalError here in a real app.
                      fatalError("Unable to initialize type \(Post.self) with dictionary \(document.data())")
                  }
              }
  
              self.posts = models
              self.documents = snapshot.documents
  
              if self.documents.count &gt; 0 {
                  self.tableView.backgroundView = nil
              } else {
                  self.tableView.backgroundView = self.backgroundView
              }
  
              self.tableView.reloadData()
              self.fetchMoreIngredients = false
              self.lastDocumentSnapshot = snapshot.documents.last
  
          }
      }
  
  func scrollViewDidScroll(_ scrollView: UIScrollView) {
  
          let off = scrollView.contentOffset.y
          let off1 = scrollView.contentSize.height
  
          if off &gt; off1 - scrollView.frame.height * leadingScreensForBatching{
              if !fetchMoreIngredients &amp;&amp; !reachEnd{
                  print(fetchMoreIngredients)
                //  beginBatchFetch()
                  // query = baseQuery()
                  observeQuery()
              }
          }
      }
  </code></pre>