Skip to content Skip to sidebar Skip to footer

How I Get All Subcollection In Document In Collection

i looking for document talk about this my problem but it look like quite quite a few i have one collection like this collection(user1)=>uid=>document( collection(Product =>

Solution 1:

If you want to get the documents from all Product collections, you can use a collection group query.

To use it, you'd do:

await firebase.firestore().collectionGroup('Product').onSnapshot(sanpham => {
  sanpham.forEach((doc) => {
    a.push({ id: doc.id, data: doc.data() })
  })
})

If you want to know which user a product belongs to, you can determine that with:

const productRef = doc.ref;
const productCollectionRef = productRef.parent;
const userRef = productCollectionRef.parent;
console.log(userRef.id); 

Post a Comment for "How I Get All Subcollection In Document In Collection"