【问题标题】:How to create two onCreate function in firebase如何在firebase中创建两个onCreate函数
【发布时间】:2020-02-20 22:42:18
【问题描述】:

我需要在两个不同的集合上触发我的函数。这个怎么做?

我有类似的东西,但是第二个函数首先覆盖并且第一个不起作用。如何做到这一点?

'使用严格'; 常量函数=要求('firebase-functions');常量管理员=需要('firebase-admin');admin.initializeApp(functions.config().firebase);常量数据库 = 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);

});```

【问题讨论】:

    标签: javascript firebase google-cloud-functions


    【解决方案1】:

    每个函数的名称必须是唯一的。现在,您给它们都赋予了相同的名称“apptTrigger”。尝试给他们起不同的名字。

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

    【讨论】:

    • 天啊,我是白痴...非常感谢。
    猜你喜欢
    • 2021-12-29
    • 2021-07-30
    • 2019-12-19
    • 2019-12-13
    • 2019-02-21
    • 2020-06-12
    • 2018-09-14
    • 2019-06-24
    • 2019-02-25
    相关资源
    最近更新 更多