I need to trigger my functions on two different collections. How to do this?
I have something like this but second function overwrites first and first doesn't work. How to do this?
'use strict'; const functions = require('firebase-functions');const admin = require('firebase-admin');admin.initializeApp(functions.config().firebase); const database = admin.database();
exports.apptTrigger = functions.firestore
.document('notification/{anydocument}' )
.onCreate((snap, context) => {
const title = snap.data().title;
const messageis = snap.data().content;
const postId = snap.data().idPost;
const payLoad = {
notification:{
title: title,
body: messageis,
sound: "default"
}
};
return admin.messaging().sendToTopic("notification", payLoad);
});
exports.apptTrigger = functions.firestore
.document('notificationP/{anydocument}')
.onCreate((snap, context) => {
const title = snap.data().title;
const messageis = snap.data().content;
const postId = snap.data().idPost;
const payLoad = {
notification:{
title: title,
body: messageis,
sound: "default"
}
};
return admin.messaging().sendToTopic("notification", payLoad);
});```