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

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

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