I'm trying to write a function for Firebase that update all the documents inside a specific collection when another type of document is updated.
functions.firestore.document('/accounts/{accountId}/resources/{resourceId}')
.onUpdate((change, context) => {
const resource = context.params.resourceId;
admin.firestore().collection('/accounts/'+account+'/tasks')
.where('resourceId', '=', resource).get().then(snapshot => {
snapshot.forEach(doc => {
doc.update({
fieldA: 'valueA',
fieldB: 'valueB'
});
});
return true;
})
.catch(error => {
console.log(error);
});
});
This is not working, but i don't know how to do it, it's the first time i make a function for Firebase.