I have created a collection with
db.collection("userCal/" currentUserUID "/activities").add({event})
and now im trying to query all of this data from firebase but i dont think im doing it correctly.
it looks like this in firebase
and inside activities it looks like this:
I have this right not but its failing.
let doc = await fire
.firestore()
.collection('userCal')
.doc(currentUserUID)
.collection("activities")
.get()
let dataObj = doc.data();
console.log(dataObj);
CodePudding user response:
When you use get()
on a CollectionReference to fetch multiple documents from that collection, it returns a QuerySnapshot unlike using get()
on a DocumentReference that just returns a DocumentSnapshot of a single document. So you'll have to run a loop on all documents present in the response as shown below:
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);