Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

105
Visualizações
startAfter function always display the same data

I'm beginner to firestore. My query always give the same data independently of the value i pass into startAfter() function.

here's code:

    const fetchMore = async () => {
        const q = query(
            collection(db, 'chat-messages'),
            orderBy('createdAt', 'asc'),
            startAfter(23),
            limit(5),
        );

        const querySnapshot = await getDocs(q)

        querySnapshot.forEach(doc => {
            console.log(doc.data())
        })
    }

Thanks for reading and helping! Have a nice day

enter image description here

here's the console.log

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I'm not sure what type the data in your startAt field is, but I guess it's a date or a Firestore Timestamp.

Pagination in Firestore is not based on numeric offsets, as you may be used to from other databases, but instead is based on so-called cursor objects: knowing the values and/or ID of the document you want to start after.

So you'll need to pass in the timestamp that you want to start after, not the number of documents you want to skip. So for example, to get all documents with a createdAt after now, you could do:

startAfter(Timestamp.now())

For more on this way of pagination, see the documentation on paginating data with query cursors.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda