Thursday, 18 May 2017

How to learn new data in Firebase cloud functions?

How do you know if the data is not changing and what's new in Firebase Cloud functions? I've tried several different options to flag that if the data is just changed, then I do not send push notification. Also I tried to get from snapshot _newData   And _data child nodes to compare the number, and if __newData is greater, then this is a new record, but it did not work. Please tell me how it can be done.

A snippet of example code.

   module.exports = functions.database.ref('/userListEvents/{userID}')
        .onWrite(event => {

            const snapshot = event.data;

            if (event.data.val() && !event.data.previous.val()) {
                console.log('send push notification');
            } else if (snapshot._data) {
                console.log('send push notification');
            } else {
                return console.log('data was removed');
            };
    }

Ref

functions.database.ref('/cards/{cardID}/interestedUsers')
    .onWrite(event => {



via Alexsander

No comments:

Post a Comment