【问题标题】:Firebase/Cloud function does not fire event on real time database deleteFirebase/Cloud 功能不会在实时数据库删除时触发事件
【发布时间】:2019-05-19 21:23:53
【问题描述】:

我正在尝试使用以下方法监听子集合上的删除:

'use strict';

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
console.log('listen for delete');
exports.sendActivityChangeNotification = functions.database.ref('/games/{gameId}/attendees/{attdendeeId}')
.onDelete(async (change, context) => {
  const gameId = context.params.gameId;
  const attdendeeId = context.params.attdendeeId;
  console.log(`activityId ${activityId} attdendeeId ${attdendeeId}` );
}

路径“/games/{gameId}/attendees/{attdendeeId}”的位置 games 是父集合 gameId 是文档,参加者是我要在删除文档时收听的集合。

这甚至可能吗?这是我第一次使用函数。我确实确保使用部署函数后存在的新数据进行测试。

感谢您的任何建议!

【问题讨论】:

    标签: firebase firebase-realtime-database google-cloud-functions


    【解决方案1】:

    您的代码访问实时数据库,但您使用了“集合”和“文档”这两个词,它们是 Firestore 术语。

    实时数据库和 Cloud Firestore 是完全不同的产品。确保为正在使用的数据库编写正确类型的触发器。如果您正在使用 Firestore,请write a Firestore trigger

    【讨论】:

      猜你喜欢
      • 2021-01-28
      • 2017-10-01
      • 1970-01-01
      • 2020-03-23
      • 2018-08-09
      • 2018-11-22
      • 2019-10-18
      • 1970-01-01
      • 2017-11-23
      相关资源
      最近更新 更多