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

123
Visualizações
Firebase/Firestore start loop from certain document ID

I'm getting a collection from my Firestore database and adding the document values to an array in JS:

var data = myCollection();

  var myArray = [];

  data.forEach(function(data) {
    var splitPath = data.name.split('/');
    var documentId = splitPath[splitPath.length - 1];
    var name = data.fields.name ? data.fields.name.stringValue : '';
    var country = data.fields.vin ? data.fields.vin.stringValue : '';

    myArray.push( [ documentId, name, country ] );
  });

Suppose I know a document ID, is it possible to get the collection documents from that certain document ID?

I'm not sure if Firestore documents are ordered by date. I am trying to get the most recent documents from a certain document ID.

about 4 years ago · Santiago Gelvez
2 Respostas
Responde à pergunta

0

Suppose I know a document ID, is it possible to get the collection documents from that certain document ID?

When it comes to the Firebase console, all documents are sorted lexicographically by ID and this behavior can't be changed. When it comes to code, it's up to you to choose how to order the results.

I'm not sure if Firestore documents are ordered by date.

No, there is no time component inside the document IDs.

I am trying to get the most recent documents from a certain document ID.

In that case, the simplest solution would be to add a timestamp field in each document and order them according to that field.

However, Firebase Realtime Database pushed IDs do contain a time component. So if you want, you can add that data there. Both databases are working great together.

If you have multiple documents and you want to implement pagination, for example, you can use query cursors and use startAt() or starAfter() if you need that.

about 4 years ago · Santiago Gelvez Relatório

0

I don't know if this is exactly what you need but firebase docs has below example:Order and limit data

import { query, where, orderBy, limit } from "firebase/firestore";  

const q = query(citiesRef, where("population", ">", 100000), orderBy("population"), limit(2));

if you adjust where part to your id, then sort by date it should work.

about 4 years ago · Santiago Gelvez 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