【问题标题】:how to update a value in firebase cloud firestore database using Cloud Functions for Firebase如何使用 Cloud Functions for Firebase 更新 Firebase Cloud Firestore 数据库中的值
【发布时间】:2019-07-14 13:34:50
【问题描述】:

我正在尝试使用云触发器功能更新云 Firestore 数据库,但每次它都会在控制台中抛出错误

我已经尝试过下面的代码,但没有成功 -

const ref = change.data().ref;
ref.update({
    "isVerified": true
});

这是我的功能-

exports.updateLisenceKey_SendEmailToOwner = functions.firestore
    .document('lisence_key/{userId}')
    .onUpdate((change, context) => {
       const ref = change.data().ref;
       ref.update({
           "isVerified": true
       });
    });

我希望该函数应该更新云 Firestore 数据库中的节点

【问题讨论】:

  • 你得到什么错误?
  • @frankvanpuffelen ``` 在 exports.updateLisenceKey_SendEmailToOwner.functions.firestore.document.onUpdate (/srv/functions/index.js:198:28)```
  • @mufaddal_mw 不够
  • @ToraCode imgur.com/7RwtUOO
  • 以上代码可以在实时数据库中运行,但在firestore云数据库中无法运行

标签: node.js firebase google-cloud-firestore google-cloud-functions


【解决方案1】:

在对 firebase 文档进行研究后,我发现可以使用以下代码从云 firestore 更新触发函数更新数据库 -

return change.after.ref.set({
          isVerified: true
        }, {merge: true});

参考- https://github.com/firebase/snippets-node/blob/9ae3a00985b53025fdc82716046882af71b6009d/firestore/extend-with-functions/functions/index.js#L108-L130

【讨论】:

  • 我使用的和上面一样,但是没有更新数据库中的值
猜你喜欢
  • 2017-09-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-30
  • 1970-01-01
  • 2019-07-05
  • 2021-01-09
  • 2020-05-31
相关资源
最近更新 更多