Firebase cloud functions stopped working - event.data undefined

后端 未结 2 436
北荒
北荒 2020-12-11 20:54

I have some cloud functionsbut they suddenly stopped working, now I\'m getting event.data undefined

exports.newMessageReceived = functions.database.ref(\'/me         


        
相关标签:
2条回答
  • 2020-12-11 20:58

    Cloud functions were updated to version 1.0, you can check here for more info:

    https://firebase.google.com/docs/functions/beta-v1-diff#realtime-database

    Regarding the question, you need to change the code into this:

    exports.newMessageReceived = functions.database.ref('/messages/{pushId}').onWrite((change,context) => {
    
    if (change.before.exists() || !change.after.exists() ) {
        //Do nothing if data is edited or deleted
        console.log('Message edited or deleted - skip');
        return;
      }
    
    }
    

    onWrite now has two parameters change and context. Change has before and after properties, and before is equivalent to previous

    Also change and before can use the methods listed here:

    https://firebase.google.com/docs/reference/admin/node/admin.database.DataSnapshot

    0 讨论(0)
  • 2020-12-11 21:17

    I had same issue.

    This is a firebase documentation showing the changes that have been made on the new v1

    https://firebase.google.com/docs/functions/beta-v1-diff

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