'Firestore - How to retrieve all subcollections of a collection
I have a question regarding Firestore, I created a "category" collection in which I have several documents, I created a "construction sites" sub-collection! I want to retrieve all my sub collections from each category, but when I try to do like this:
useEffect(() => {
const listConstruction = [];
db.collection('category').get().then((collectionCategory) => {
collectionCategory.forEach((doc) => {
doc.ref.collection('construction').get().then((collectionConstruction) => {
collectionConstruction.forEach((doc1) => {
listConstruction.push({
idCategory: doc.id,
libelleCategory: doc.data().libelle,
title: doc1.data().title,
description: doc1.data().description,
});
});
});
});
}).finally(() => {
setConstruction(listConstruction);
});
}, []);
The problem is that it hasn't finished pushing the constructs it passes into my finally!
Having no experience with NoSQL and Firestore yet, I would have liked if I'm not completely wrong about its use and if so how to fix it?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
