Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

419
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!