我創建了一個集合
db.collection("userCal/" currentUserUID "/activities").add({event})
現在我試圖從firebase查詢所有這些資料,但我認為我做得不對。
在firebase中看起來像這樣

內部活動看起來像這樣:

我沒有這個權利,但它失敗了。
let doc = await fire
.firestore()
.collection('userCal')
.doc(currentUserUID)
.collection("activities")
.get()
let dataObj = doc.data();
console.log(dataObj);
uj5u.com熱心網友回復:
當您get()在CollectionReference上使用從該集合中獲取多個檔案時,它會回傳一個QuerySnapshot ,這與get()在DocumentReference上使用僅回傳單個檔案的 DocumentSnapshot不同。因此,您必須對回應中存在的所有檔案運行一個回圈,如下所示:
const qSnap = await fire
.firestore()
.collection('userCal')
.doc(currentUserUID)
.collection("activities")
.get()
const data = qSnap.docs.map(d => ({ id: d.id, ...d.data() }))
console.log(data);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/431304.html
標籤:javascript 火力基地 谷歌云火库 反应钩子
