I am trying to export a firestore function that performs a query and returns an array containing the objects in that query. I am trying to get data from a subcollection of a document, and get an array of document objects returned to render to the client.
I've tried the below but it's not working (e.g. the object returns blank). I think this has to do with improper handling of promises, but couldn't figure it out on my own. Thanks for your help.
export const getEvents = (id) => {
let events = [];
firestore.collection('users')
.doc(id)
.collection('events')
.get()
.then((snapshot) => {
snapshot.forEach((doc) => events.push(doc));
});
return events;
};