Reputation: 2061
I have this code below which works (no syntax or any other errors) except that the output of this code displays all the results under /server/name
:
i.e:
We have a new event:
{ des: 'test123', name: 'Test', nice: 'wew' } lol
Here is the Code in functions/index.js:
exports.sendFollowerNotification = functions.database.ref('/server/name').onWrite(event => {
admin.database().ref("/server/name").limitToLast(1).on('child_added', function(snapshot) {
console.log('We have a new event:', snapshot.val());
});
Here is the DB:
exports.sendFollowerNotification = functions.database.ref('/server/name/{num}').onWrite(event => {
console.log('We have a new event:', event.data.val(), 'lol');
});
Output in Logs:
And
Upvotes: 0
Views: 230
Reputation: 7546
Currently, the trigger is attached higher in the path than you want.
Instead,if you're planning on having multiple lists of events to listen to and this is just list 1 of many, use a wildcard:
exports.sendFollowerNotification = functions.database.ref('/server/name/{num}/{notification}').onWrite(event => {
...
})
You can choose wildcard names that better fit your specific code.
Upvotes: 2