Search code examples
javascriptreactjsfirebasegoogle-cloud-firestore

Got same response from firestore while retriving data using startAfter


if (startAfterDoc) {
  q = query(collection(db, 'listings'), orderBy("id","desc"), startAfter(startAfterDoc), limit(4));
  console.log(q)
} else {
  q = query(collection(db, 'listings'), orderBy("id","desc"), limit(3));
}

For startAfterDoc I'm using whole doc as input.

Image when startafterdoc not defined:

enter image description here

Image when startafterdoc is defined:

enter image description here


Solution

  • Got the solution I passed the whole document in startAfter, but then I realized I was ordering by id. When I passed the document id instead, it worked perfectly

     if (startAfterDoc) {
              q = query(collection(db, 'listings'), orderBy("id","desc"), startAfter(startAfterDoc.id), limit(4));
            } else {
              q = query(collection(db, 'listings'), orderBy("id","desc"), limit(3));
            }