so I have this collection:
//console.log(currentUserUID)
await fire
.firestore()
.collection('userEventsCal')
.doc(currentUserUID)
.collection(eventID)
.get()
I am calling this in a new page, so I don't have access to the eventID. I am trying to figure out how to do it with just
await fire
.firestore()
.collection('userEventsCal')
.doc(currentUserUID)
but it's failing. Is my logic wrong or is this just impossible to do?
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);
});
It looks like this in firebase:
I understand that you want to list the subcollections of the document with the DocumentReference corresponding to firestore().collection('userEventsCal').doc(currentUserUID).
As a matter of fact, retrieving a list of collections is not possible with the mobile/web client libraries, as explained in the Firestore documentation.
I wrote an article which proposes solutions to this problem: How to list all subcollections of a Cloud Firestore document?.
Basically, you can either save the list in a dedicated field of the parent document or use a Cloud Function.
At first glance it seems the first approach is probably the most interesting one in your case. Note however the 1MB limit for a document.