I made a junction collection in containing references to other collections. Is it possible to get the data of the junction collection AS WELL AS the other collections data in one go?
This is an example of my Firestore schema! For now I been looping through the field (eg. competitors) to get the data from firestore, but obviously we would like to lessen the count of call outwards. Please help thank you!
CodePudding user response:
There's no way to query all those references at once. You'll have run those separate query separately. You can try the following:
const getData = async () => {
const groupRef = doc(db, "competitor_groups", "group_id");
const groupSnap = await getDoc(groupRef);
const eventsPromises = groupSnap.data().events.map((ev) => getDoc(ev))
const eventsData = eventsPromises.map((ev) => ev.data());
console.log(eventsData)
const eventsSnap = await Promise.all(eventsPromises);
}