node js function onWrite is not working properly in google cloud function

前端 未结 1 792
傲寒
傲寒 2021-01-28 23:45

I have this node js function that attempts to update Algolia index once a add/update/delete is done to node Listings

exports.indexlisting_algolia = 
    function         


        
相关标签:
1条回答
  • 2021-01-28 23:57

    You're using an old version of the API exposed by the firebase-functions module. The new one requires that you accept a Change object, with before and after attributes, as the first parameter of onWrite and onUpdate triggers. Those attributes will be DataSnapshot objets. Your code is currently expecting a DataDeltaSnapshot, which is what you got in the beta version before the full 1.0 release. This is now deprecated.

    You can read about the API changes in version 1.0 in the documentation.

    Please also see the documentation for database triggers for examples.

    Your function should look more like this:

    exports.indexlisting_algolia = 
        functions.database.ref('/Listings/{listingId}')
        .onWrite((change, context) => {
            const before = change.before;  // snapshot before the update
            const after = change.after;    // snapshot after the update
            const before_data = before.val();
            const afater_data = after.val();
        })
    
    0 讨论(0)
提交回复
热议问题