更新时间:2023-02-14 08:53:32
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);