[英]Get the ID of firebase document
所以我有這個系列:
//console.log(currentUserUID)
await fire
.firestore()
.collection('userEventsCal')
.doc(currentUserUID)
.collection(eventID)
.get()
我在新頁面中調用它,所以我無權訪問 eventID。 我想弄清楚如何做到這一點
await fire
.firestore()
.collection('userEventsCal')
.doc(currentUserUID)
但它失敗了。 我的邏輯是錯誤的還是這是不可能的?
await fire
.firestore()
.collection('userEventsCal')
.doc(currentUserUID)
.get().then((doc) => {
if (doc.exists) {
console.log("Doc data lol:", doc.data());
} else {
// doc.data() will be undefined in this case
console.log("No such document!");
}
}).catch((error) => {
console.log("Error getting document:", error);
});
在 firebase 中看起來是這樣的:
我知道您想列出文檔的子集合,其中DocumentReference
對應於firestore().collection('userEventsCal').doc(currentUserUID)
。
事實上,如Firestore 文檔中所述,移動/Web 客戶端庫無法檢索 collections 的列表。
我寫了一篇文章提出了這個問題的解決方案: How to list all subcollections of a Cloud Firestore document? .
基本上,您可以將列表保存在父文檔的專用字段中或使用 Cloud Function。
乍一看,第一種方法可能是您的案例中最有趣的方法。 但是請注意文檔的 1MB 限制。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.