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

81
Vistas
Need to get an array of all Id's in a firebase collection

Have the method below that extracts the Id's from the firebase collection and pushes it to an array, BUT it makes each document into an array. In other words- if i have 100 documents in the collection - it makes 100 arrays inside the array IDarray. I just need one array to keep it more efficient. Maybe:)

     db.collection('Customers')
     .orderBy('createdAt', 'asc')
     .get()
     .then((data) => {
                      let IDarray = [];
                      data.docs.forEach(doc =>{
                      IDarray.push(+doc.id);
                      });
       return [IDarray];
     })

I can certainly make this work but if anyone knows of a better way so the system is not generating all the extra arrays it would be appreciated. (Back story: the IDarray is being generated as int because my Id's for the collection are a number sequence) Cheers!

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Try this:

  db
    .collection("Customers")
    .orderBy("createdAt", "asc")
    .get()
    .then((data) => {
      let IDarray = [];
      data.docs.forEach((doc) => {
        IDarray.push(+doc.id);
      });
      return IDarray;
    });

It works just fine for me.

Or here's an ES6-y way of doing it:

  db
    .collection("Customers")
    .orderBy("createdAt", "asc")
    .get()
    .then(({ docs }) => docs.map(({ id }) => +id));
about 4 years ago · Juan Pablo Isaza Denunciar

0

Seems like you don't need another array wrapper for the return value:

    return IDarray;

Notice no square braces. Just return the array as-is.

about 4 years ago · Juan Pablo Isaza 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