I know that this question is already asked but it didn't help. I have a "chats" collection with one document "members" and a sub-collection "messages" and I would like to trigger a cloud function when a new message is added in the sub-collection.
This is what I tried but it is only triggered when "members" is updated, and does not have any information on the sub-collection:
exports.chatsCollectionTriggers = functions.firestore.document('/chats/{chatId}/messages/{messageId}').onUpdate(async (change, context) => {
let chatBefore = change.before.data();
let chatAfter = change.after.data();
console.log(JSON.stringify(chatBefore, null, 2));
console.log(JSON.stringify(chatAfter, null, 2));
console.log(context.params.chatId);
console.log(context.params.messageId);});
My question is how can I trigger a cloud function on a sub-collection update ?