Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

124
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda