【发布时间】:2017-10-10 12:46:06
【问题描述】:
我该怎么做?我使用了下面的代码,但它不起作用。当我更新我的数据库时,我仍然会收到通知
exports.sendNewPostNotif = functions.database.ref('/News/{ID}').onWrite(event => {
const announce_data = event.data.val();
const announce_data_type = announce_data.categ_post;
const announce_data_title = announce_data.title_post;
const announce_data_uid = announce_data.uid; id
const announce_post_key = announce_data.postkey;
if(!event.data.val()) {
return console.log('No data');
}
if(event.data.previous.exist()) {
return;
}
每当我发送新内容时,它都会通过 onWrite 事件然后发送通知。我当前的问题是每当我编辑帖子时,它都会发送我不需要的通知。我尝试了上述方法,它可以正常工作,因为我在更新新闻内容时没有收到通知,但在创建新内容时没有收到通知。
【问题讨论】:
-
没有看到minimal complete code that reproduces the problem,将很难提供帮助。我们在这里遗漏了很多上下文。这段代码在哪里运行?
event是什么? -
对不起,如果我让你感到困惑。
-
@FrankvanPuffelen 是否可以使用 event.data.key 来检查它之前是否存在?
标签: android firebase firebase-realtime-database google-cloud-functions