如何在firebase中创建两个onCreate函数



我需要在两个不同的集合上触发函数。如何做到这一点?

我有这样的东西,但第二个函数覆盖了第一个,第一个不起作用。如何做到这一点?

"严格使用";const函数=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);
});```

每个函数的名称必须是唯一的。现在,您给它们取了相同的名称"apptTrigger"。试着给他们起不同的名字。

exports.apptTriggerNotification = functions.firestore...
exports.apptTriggerNotificationP = functions.firestore...

最新更新