I have two collections: Db.collection(groups) Db.collection(users) The group doc stores a map of members. Id like to fire a function which iterates over the collection, storing aggregated data from the user document (eg. Number activities last week) How to handle this, if the collection contains many documents?
I would solve this with a promise. But i guess i run into limits of collection.get() or a timeout during the forEach loop. Is a paginated read (.startAt()) the solution here? What about the timeout?
export const someMethod = functions.https.onRequest((req, res) => {
let stuff: any[] = [];
let db = getFirestore();
db.collection("groups").get().then(snapshot => {
snapshot.forEach(doc => {
var newelement = {
"Members.${doc.id}.activities": doc.data().activities.lenth }
//batched write for every doc
// ...
});
res.send("ok")
return "";
}).catch(reason => {
res.send(reason)
})
});