how to update a value in firebase realtime database using Cloud Functions for Firebase

前端 未结 1 1664
鱼传尺愫
鱼传尺愫 2021-02-05 17:48

I went though the firebase docs for updating a value in realtime database using Cloud Functions for Firebase, but am not able to understand.

My database structure is

1条回答
  •  一整个雨季
    2021-02-05 18:24

    You are trying to call update() on a DeltaSnapshot object. There is no such method on that type of object.

    var eventSnapshot = event.data;
    eventSnapshot.update({
        "isVerified": true
    });
    

    event.data is a DeltaSnapshot. If you want to change the data at the location of the change represented by this object. Use its ref property to get a hold of a Reference object:

    var ref = event.data.ref;
    ref.update({
        "isVerified": true
    });
    

    Also, if you are reading or writing the database in a function, you should always return a Promise that indicates when the change is complete:

    return ref.update({
        "isVerified": true
    });
    

    I would recommend taking Frank's advice from the comments and study the existing sample code and documentation to better understand how Cloud Functions works.

    0 讨论(0)
提交回复
热议问题