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

417
Visualizações
How to list all subcollections of a Firestore document?

enter image description hereenter image description here

Hi, I have a problem with downloading all collections from the document. I would like after finding the id (userUid) document to be able to download all its collections, I need the id of each of these collection

export const getAllMessagesByUserId = async (userUid) => {
  const result = await firebase
    .firestore()
    .collection('messages')
    .doc(userUid)
    .onSnapshot((snapshot) => {
      console.log(snapshot);
    });

};
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I wrote an article which proposes solutions to this problem: How to list all subcollections of a Cloud Firestore document? As a matter of fact, "retrieving a list of collections is not possible with the mobile/web client libraries" as explained in the Firestore documentation.

I would suggest you use the second method proposed in the article, using a Cloud Function.

Here is the code copied from the article.

Cloud Function:

const functions = require('firebase-functions');
const admin = require('firebase-admin');

admin.initializeApp();

exports.getSubCollections = functions.https.onCall(async (data, context) => {

    const docPath = data.docPath;

    const collections = await admin.firestore().doc(docPath).listCollections();
    const collectionIds = collections.map(col => col.id);

    return { collections: collectionIds };

});

Example of calling the Cloud Function from a web app:

  const getSubCollections = firebase
    .functions()
    .httpsCallable('getSubCollections');

  getSubCollections({ docPath: 'collectionId/documentId' })
    .then(function(result) {
      var collections = result.data.collections;
      console.log(collections);
    })
    .catch(function(error) {
      // Getting the Error details.
      var code = error.code;
      var message = error.message;
      var details = error.details;
      // ...
    });
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