【问题标题】:Firebase cloud function only triggering when I manually add data to firestore from consoleFirebase 云功能仅在我从控制台手动将数据添加到 Firestore 时触发
【发布时间】:2018-07-20 15:04:30
【问题描述】:

当我以编程方式将内容添加到 firestore 时,我的函数不会触发,它只会在我从控制台手动添加数据时执行。

这是我的功能:

exports.updateFirestoreStatistics = functions.firestore.document('applications/2018/all/{app}').onWrite(change => {
  let ref = db.collection('statistics').doc('2018');
  let t = db.runTransaction(transaction => {
    return transaction.get(ref).then(doc => {
      let updatedAppCount = doc.data().applications + 1
      return transaction.update(ref, {applications: updatedAppCount});
    })
  }).then(() => console.log('Stat updated! ')).catch(err => console.log('An error occured ', err));
});

【问题讨论】:

  • {app] 是文档还是集合?
  • @RodrigoMata 一个文档
  • 你能展示你用来以编程方式添加“东西”的代码吗?以编程方式添加数据后,它会显示在控制台中吗?

标签: javascript firebase google-cloud-firestore google-cloud-functions


【解决方案1】:

你应该返回异步runTransaction()方法返回的Promise。

如果您不这样做,运行您的函数的 Cloud Functions 实例可能会在您的函数成功执行事务之前关闭。

我建议您观看 Firebase 团队的以下 2 个视频:https://www.youtube.com/watch?v=7IkUgCLr5oAhttps://www.youtube.com/watch?v=652XeeKNHSk

【讨论】:

  • 嗨@kumail。您有时间查看建议的解决方案吗?
猜你喜欢
  • 1970-01-01
  • 2019-01-20
  • 1970-01-01
  • 2018-06-30
  • 2018-05-09
  • 1970-01-01
  • 2019-02-02
  • 1970-01-01
  • 2021-11-27
相关资源
最近更新 更多