簡體   English   中英

如何使用Cloud Functions for Firebase更新Firebase Cloud Firestore數據庫中的值

[英]how to update a value in firebase cloud firestore database using Cloud Functions for Firebase

我正在嘗試使用雲觸發器功能來更新Cloud 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
       });
    });

我希望該功能應更新Cloud Firestore數據庫中的節點

在研究了Firebase文檔之后,我發現可以使用以下代碼從Cloud Firestore更新觸發器功能更新數據庫-

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM