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

84
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 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